http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/shell/GfshExitCodeStatusCommandsTest.java ---------------------------------------------------------------------- diff --git a/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/shell/GfshExitCodeStatusCommandsTest.java b/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/shell/GfshExitCodeStatusCommandsTest.java new file mode 100755 index 0000000..bc309dd --- /dev/null +++ b/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/shell/GfshExitCodeStatusCommandsTest.java @@ -0,0 +1,391 @@ +/* + * 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.shell; + +import static java.util.concurrent.TimeUnit.MINUTES; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import junitparams.JUnitParamsRunner; +import junitparams.Parameters; +import org.junit.Assume; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import org.apache.geode.internal.AvailablePort; +import org.apache.geode.internal.ExitCode; +import org.apache.geode.internal.process.PidFile; +import org.apache.geode.management.internal.cli.util.CommandStringBuilder; +import org.apache.geode.management.internal.cli.util.ThreePhraseGenerator; +import org.apache.geode.test.dunit.rules.gfsh.GfshExecution; +import org.apache.geode.test.dunit.rules.gfsh.GfshRule; +import org.apache.geode.test.dunit.rules.gfsh.GfshScript; +import org.apache.geode.test.junit.categories.AcceptanceTest; + +// Originally created in response to GEODE-2971 + +@Category(AcceptanceTest.class) +@RunWith(JUnitParamsRunner.class) +public class GfshExitCodeStatusCommandsTest { + private static File toolsJar; + private static final ThreePhraseGenerator nameGenerator = new ThreePhraseGenerator(); + private static final String memberControllerName = "member-controller"; + + @Rule + public GfshRule gfsh = new GfshRule(); + private String locatorName; + private String serverName; + + private int locatorPort; + + // Some test configuration shorthands + private static final TestConfiguration LOCATOR_ONLINE_BUT_NOT_CONNECTED = + new TestConfiguration(true, false, false); + private static final TestConfiguration LOCATOR_ONLINE_AND_CONNECTED = + new TestConfiguration(true, false, true); + private static final TestConfiguration BOTH_ONLINE_BUT_NOT_CONNECTED = + new TestConfiguration(true, true, false); + private static final TestConfiguration BOTH_ONLINE_AND_CONNECTED = + new TestConfiguration(true, true, true); + + @BeforeClass + public static void classSetup() { + File javaHome = new File(System.getProperty("java.home")); + String toolsPath = + javaHome.getName().equalsIgnoreCase("jre") ? "../lib/tools.jar" : "lib/tools.jar"; + toolsJar = new File(javaHome, toolsPath); + } + + @Before + public void setup() { + locatorName = "locator-" + nameGenerator.generate('-'); + serverName = "server-" + nameGenerator.generate('-'); + locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); + } + + @Test + @Parameters( + value = {"status locator --port=-10", "status locator --pid=-1", "status server --pid=-1"}) + public void statusCommandWithInvalidOptionValueShouldFail(String cmd) { + GfshScript.of(cmd).withName("test-frame").awaitAtMost(1, MINUTES) + .expectExitCode(ExitCode.FATAL.getValue()).execute(gfsh); + } + + + @Test + @Parameters(value = {"status locator --host=somehostname", "status locator --port=10334", + "status locator --dir=.", "status server --dir=.", "status locator --name=some-locator-name", + "status server --name=some-server-name", "status locator --pid=100", + "status server --pid=100"}) + public void statusCommandWithValidOptionValueShouldFailWithNoMembers(String cmd) { + GfshScript.of(cmd).withName("test-frame").awaitAtMost(1, MINUTES) + .expectExitCode(ExitCode.FATAL.getValue()).execute(gfsh); + } + + + @Test + public void onlineStatusCommandShouldFailWhenNotConnected_locator_name() { + TestConfiguration config = LOCATOR_ONLINE_BUT_NOT_CONNECTED; + config.startNecessaryMembers(startLocatorCommand(), startServerCommand(), gfsh); + + String statusCommand = statusLocatorCommandByName(); + executeScriptWithExpectedExitCode(statusCommand, config, ExitCode.FATAL); + } + + + @Test + public void onlineStatusCommandShouldFailWhenNotConnected_server_name() { + TestConfiguration config = BOTH_ONLINE_BUT_NOT_CONNECTED; + config.startNecessaryMembers(startLocatorCommand(), startServerCommand(), gfsh); + + String statusCommand = statusServerCommandByName(); + executeScriptWithExpectedExitCode(statusCommand, config, ExitCode.FATAL); + } + + @Test + public void offlineStatusCommandShouldSucceedWhenNotConnected_locator_port() { + // --host defaults to localhost, so `status locator --port=xxx` should still succeed. + TestConfiguration config = LOCATOR_ONLINE_BUT_NOT_CONNECTED; + config.startNecessaryMembers(startLocatorCommand(), startServerCommand(), gfsh); + + String statusCommand = statusLocatorCommandByPort(); + executeScriptWithExpectedExitCode(statusCommand, config, ExitCode.NORMAL); + } + + @Test + public void offlineStatusCommandShouldSucceedWhenNotConnected_locator_host_and_port() { + // Since this is still local to the testing VM's machine, `status locator --host=localhost + // --port=xxx` should succeed + TestConfiguration config = LOCATOR_ONLINE_BUT_NOT_CONNECTED; + config.startNecessaryMembers(startLocatorCommand(), startServerCommand(), gfsh); + + String statusCommand = statusLocatorCommandByHostAndPort(); + executeScriptWithExpectedExitCode(statusCommand, config, ExitCode.NORMAL); + } + + + + @Test + public void onlineStatusCommandShouldSucceedWhenConnected_locator_name() { + TestConfiguration config = LOCATOR_ONLINE_AND_CONNECTED; + config.startNecessaryMembers(startLocatorCommand(), startServerCommand(), gfsh); + + String statusCommand = statusLocatorCommandByName(); + executeScriptWithExpectedExitCode(statusCommand, config, ExitCode.NORMAL); + } + + + @Test + public void onlineStatusCommandShouldSucceedWhenConnected_server_name() { + TestConfiguration config = BOTH_ONLINE_AND_CONNECTED; + config.startNecessaryMembers(startLocatorCommand(), startServerCommand(), gfsh); + + String statusCommand = statusServerCommandByName(); + executeScriptWithExpectedExitCode(statusCommand, config, ExitCode.NORMAL); + } + + @Test + public void onlineStatusCommandShouldSucceedWhenConnected_locator_port() { + TestConfiguration config = LOCATOR_ONLINE_AND_CONNECTED; + config.startNecessaryMembers(startLocatorCommand(), startServerCommand(), gfsh); + + String statusCommand = statusLocatorCommandByPort(); + executeScriptWithExpectedExitCode(statusCommand, config, ExitCode.NORMAL); + } + + @Test + public void onlineStatusCommandShouldSucceedWhenConnected_locator_host_and_port() { + TestConfiguration config = LOCATOR_ONLINE_AND_CONNECTED; + config.startNecessaryMembers(startLocatorCommand(), startServerCommand(), gfsh); + + String statusCommand = statusLocatorCommandByHostAndPort(); + executeScriptWithExpectedExitCode(statusCommand, config, ExitCode.NORMAL); + } + + + + @Test + public void offlineStatusCommandShouldSucceedWhenConnected_locator_dir() { + TestConfiguration config = LOCATOR_ONLINE_AND_CONNECTED; + config.startNecessaryMembers(startLocatorCommand(), startServerCommand(), gfsh); + + String statusCommand = statusLocatorCommandByDir(); + executeScriptWithExpectedExitCode(statusCommand, config, ExitCode.NORMAL); + } + + @Test + public void offlineStatusCommandShouldSucceedWhenConnected_server_dir() { + TestConfiguration config = BOTH_ONLINE_AND_CONNECTED; + config.startNecessaryMembers(startLocatorCommand(), startServerCommand(), gfsh); + + String statusCommand = statusServerCommandByDir(); + executeScriptWithExpectedExitCode(statusCommand, config, ExitCode.NORMAL); + } + + @Test + public void offlineStatusCommandShouldSucceedWhenConnected_locator_pid() throws IOException { + Assume.assumeTrue(toolsJar.exists()); + TestConfiguration config = LOCATOR_ONLINE_AND_CONNECTED; + config.startNecessaryMembers(startLocatorCommand(), startServerCommand(), gfsh); + + String statusCommand = statusLocatorCommandByPid(); + executeScriptWithExpectedExitCode(statusCommand, config, ExitCode.NORMAL); + } + + @Test + public void offlineStatusCommandShouldSucceedWhenConnected_server_pid() throws IOException { + Assume.assumeTrue(toolsJar.exists()); + TestConfiguration config = BOTH_ONLINE_AND_CONNECTED; + config.startNecessaryMembers(startLocatorCommand(), startServerCommand(), gfsh); + + String statusCommand = statusServerCommandByPid(); + executeScriptWithExpectedExitCode(statusCommand, config, ExitCode.NORMAL); + } + + + + @Test + public void offlineStatusCommandShouldSucceedEvenWhenNotConnected_locator_dir() { + TestConfiguration config = LOCATOR_ONLINE_BUT_NOT_CONNECTED; + config.startNecessaryMembers(startLocatorCommand(), startServerCommand(), gfsh); + + String statusCommand = statusLocatorCommandByDir(); + executeScriptWithExpectedExitCode(statusCommand, config, ExitCode.NORMAL); + } + + @Test + public void offlineStatusCommandShouldSucceedEvenWhenNotConnected_server_dir() { + TestConfiguration config = BOTH_ONLINE_BUT_NOT_CONNECTED; + config.startNecessaryMembers(startLocatorCommand(), startServerCommand(), gfsh); + + String statusCommand = statusServerCommandByDir(); + executeScriptWithExpectedExitCode(statusCommand, config, ExitCode.NORMAL); + } + + @Test + public void offlineStatusCommandShouldSucceedEvenWhenNotConnected_locator_pid() + throws IOException { + Assume.assumeTrue(toolsJar.exists()); + TestConfiguration config = LOCATOR_ONLINE_BUT_NOT_CONNECTED; + config.startNecessaryMembers(startLocatorCommand(), startServerCommand(), gfsh); + + String statusCommand = statusLocatorCommandByPid(); + executeScriptWithExpectedExitCode(statusCommand, config, ExitCode.NORMAL); + } + + @Test + public void offlineStatusCommandShouldSucceedEvenWhenNotConnected_server_pid() + throws IOException { + Assume.assumeTrue(toolsJar.exists()); + TestConfiguration config = BOTH_ONLINE_BUT_NOT_CONNECTED; + config.startNecessaryMembers(startLocatorCommand(), startServerCommand(), gfsh); + + String statusCommand = statusServerCommandByPid(); + executeScriptWithExpectedExitCode(statusCommand, config, ExitCode.NORMAL); + } + + + + private String startLocatorCommand() { + return new CommandStringBuilder("start locator").addOption("name", locatorName) + .addOption("port", String.valueOf(locatorPort)).toString(); + } + + + private String startServerCommand() { + return new CommandStringBuilder("start server").addOption("name", serverName).toString(); + } + + + private String connectCommand() { + return new CommandStringBuilder("connect") + .addOption("locator", String.format("localhost[%d]", locatorPort)).toString(); + } + + + private String statusServerCommandByName() { + return new CommandStringBuilder("status server").addOption("name", serverName).toString(); + } + + private String statusServerCommandByDir() { + String serverDir = gfsh.getTemporaryFolder().getRoot().toPath().resolve(memberControllerName) + .resolve(serverName).toAbsolutePath().toString(); + return new CommandStringBuilder("status server").addOption("dir", serverDir).toString(); + } + + + private String statusServerCommandByPid() throws IOException { + int serverPid = snoopMemberFile(serverName, "server.pid"); + return new CommandStringBuilder("status server").addOption("pid", String.valueOf(serverPid)) + .toString(); + } + + private String statusLocatorCommandByName() { + return new CommandStringBuilder("status locator").addOption("name", locatorName).toString(); + } + + private String statusLocatorCommandByPort() { + return new CommandStringBuilder("status locator").addOption("port", String.valueOf(locatorPort)) + .toString(); + } + + private String statusLocatorCommandByHostAndPort() { + return new CommandStringBuilder("status locator").addOption("host", "localhost") + .addOption("port", String.valueOf(locatorPort)).toString(); + } + + private String statusLocatorCommandByDir() { + String locatorDir = gfsh.getTemporaryFolder().getRoot().toPath().resolve(memberControllerName) + .resolve(locatorName).toAbsolutePath().toString(); + return new CommandStringBuilder("status locator").addOption("dir", locatorDir).toString(); + } + + + private String statusLocatorCommandByPid() throws IOException { + int locatorPid = snoopMemberFile(locatorName, "locator.pid"); + return new CommandStringBuilder("status locator").addOption("pid", String.valueOf(locatorPid)) + .toString(); + } + + private int snoopMemberFile(String memberName, String pidFileEndsWith) throws IOException { + File directory = gfsh.getTemporaryFolder().getRoot().toPath().resolve(memberControllerName) + .resolve(memberName).toFile(); + File[] files = directory.listFiles(); + if (files == null) { + throw new RuntimeException(String.format( + "Expected directory ('%s') for member '%s' either does not denote a directory, or an I/O error occurred.", + directory.toString(), memberName)); + } + File pidFile = Arrays.stream(files).filter(file -> file.getName().endsWith(pidFileEndsWith)) + .findFirst().orElseThrow(() -> new RuntimeException(String + .format("Expected member '%s' to have pid file but could not find it.", memberName))); + return new PidFile(pidFile).readPid(); + } + + private void executeScriptWithExpectedExitCode(String statusCommand, TestConfiguration config, + ExitCode expectedExit) { + + String[] gfshScriptCommands = config.connectedToLocator + ? new String[] {connectCommand(), statusCommand} : new String[] {statusCommand}; + GfshScript gfshScript = GfshScript.of(gfshScriptCommands).withName("test-frame") + .awaitAtMost(1, MINUTES).expectExitCode(expectedExit.getValue()); + if (toolsJar.exists()) { + gfshScript.addToClasspath(toolsJar.getAbsolutePath()); + } + gfshScript.execute(gfsh); + } + + + private static class TestConfiguration { + TestConfiguration(boolean locatorStarted, boolean serverStarted, boolean connectedToLocator) { + this.locatorStarted = locatorStarted; + this.serverStarted = serverStarted; + this.connectedToLocator = connectedToLocator; + } + + private boolean locatorStarted; + private boolean serverStarted; + private boolean connectedToLocator; + + void startNecessaryMembers(String startLocator, String startServer, GfshRule gfsh) { + if (!locatorStarted && !serverStarted) { + return; + } + + List<String> commands = new ArrayList<>(); + if (locatorStarted) { + commands.add(startLocator); + } + if (serverStarted) { + commands.add(startServer); + } + + GfshExecution exec = GfshScript.of(commands.toArray(new String[] {})) + .withName(memberControllerName).awaitAtMost(1, MINUTES).execute(gfsh); + if (exec.getProcess().exitValue() != 0) { + throw new RuntimeException( + "The locator and server launcher exited with non-zero exit code. This failure is beyond the scope of this test."); + } + } + } +}
http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-assembly/src/test/java/org/apache/geode/test/dunit/rules/gfsh/ProcessLogger.java ---------------------------------------------------------------------- diff --git a/geode-assembly/src/test/java/org/apache/geode/test/dunit/rules/gfsh/ProcessLogger.java b/geode-assembly/src/test/java/org/apache/geode/test/dunit/rules/gfsh/ProcessLogger.java index 85a94fa..47f0304 100644 --- a/geode-assembly/src/test/java/org/apache/geode/test/dunit/rules/gfsh/ProcessLogger.java +++ b/geode-assembly/src/test/java/org/apache/geode/test/dunit/rules/gfsh/ProcessLogger.java @@ -36,14 +36,14 @@ public class ProcessLogger { private final Queue<String> stdOutLines = new ConcurrentLinkedQueue<>(); private final Queue<String> stdErrorLines = new ConcurrentLinkedQueue<>(); + private final StreamGobbler stdOutGobbler; + private final StreamGobbler stdErrGobbler; public ProcessLogger(Process process, String name) { this.logger = LOGGER_CONTEXT.getLogger(name); - StreamGobbler stdOutGobbler = - new StreamGobbler(process.getInputStream(), this::consumeInfoMessage); - StreamGobbler stdErrGobbler = - new StreamGobbler(process.getErrorStream(), this::consumeErrorMessage); + this.stdOutGobbler = new StreamGobbler(process.getInputStream(), this::consumeInfoMessage); + this.stdErrGobbler = new StreamGobbler(process.getErrorStream(), this::consumeErrorMessage); stdOutGobbler.startInNewThread(); stdErrGobbler.startInNewThread(); @@ -84,7 +84,7 @@ public class ProcessLogger { } public List<String> getStdErrLines() { - return Lists.newArrayList(stdErrorLines.iterator()); + return Lists.newArrayList(stdOutLines.iterator()); } } http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/main/java/org/apache/geode/management/internal/cli/Launcher.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/Launcher.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/Launcher.java index dc8f5f1..157bb91 100755 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/Launcher.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/Launcher.java @@ -100,6 +100,7 @@ public class Launcher { this.allowedCommandLineCommands.add(CliStrings.START_JCONSOLE); this.allowedCommandLineCommands.add(CliStrings.START_JVISUALVM); this.allowedCommandLineCommands.add(CliStrings.START_LOCATOR); + this.allowedCommandLineCommands.add(CliStrings.START_MANAGER); this.allowedCommandLineCommands.add(CliStrings.START_SERVER); this.allowedCommandLineCommands.add(CliStrings.START_VSD); this.allowedCommandLineCommands.add(CliStrings.STATUS_LOCATOR); http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/AlterOfflineDiskStoreCommand.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/AlterOfflineDiskStoreCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/AlterOfflineDiskStoreCommand.java deleted file mode 100644 index ce7594e..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/AlterOfflineDiskStoreCommand.java +++ /dev/null @@ -1,141 +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 java.io.File; - -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; - -import org.apache.geode.cache.CacheExistsException; -import org.apache.geode.cache.Region; -import org.apache.geode.internal.cache.DiskStoreImpl; -import org.apache.geode.management.cli.CliMetaData; -import org.apache.geode.management.cli.Result; -import org.apache.geode.management.internal.cli.i18n.CliStrings; -import org.apache.geode.management.internal.cli.result.ErrorResultData; -import org.apache.geode.management.internal.cli.result.ResultBuilder; - -public class AlterOfflineDiskStoreCommand implements GfshCommand { - @CliCommand(value = CliStrings.ALTER_DISK_STORE, help = CliStrings.ALTER_DISK_STORE__HELP) - @CliMetaData(shellOnly = true, relatedTopic = {CliStrings.TOPIC_GEODE_DISKSTORE}) - public Result alterOfflineDiskStore( - @CliOption(key = CliStrings.ALTER_DISK_STORE__DISKSTORENAME, mandatory = true, - help = CliStrings.ALTER_DISK_STORE__DISKSTORENAME__HELP) String diskStoreName, - @CliOption(key = CliStrings.ALTER_DISK_STORE__REGIONNAME, mandatory = true, - help = CliStrings.ALTER_DISK_STORE__REGIONNAME__HELP) String regionName, - @CliOption(key = CliStrings.ALTER_DISK_STORE__DISKDIRS, - help = CliStrings.ALTER_DISK_STORE__DISKDIRS__HELP, mandatory = true) String[] diskDirs, - @CliOption(key = CliStrings.ALTER_DISK_STORE__COMPRESSOR, specifiedDefaultValue = "none", - help = CliStrings.ALTER_DISK_STORE__COMPRESSOR__HELP) String compressorClassName, - @CliOption(key = CliStrings.ALTER_DISK_STORE__CONCURRENCY__LEVEL, - help = CliStrings.ALTER_DISK_STORE__CONCURRENCY__LEVEL__HELP) Integer concurrencyLevel, - @CliOption(key = CliStrings.ALTER_DISK_STORE__STATISTICS__ENABLED, - help = CliStrings.ALTER_DISK_STORE__STATISTICS__ENABLED__HELP) Boolean statisticsEnabled, - @CliOption(key = CliStrings.ALTER_DISK_STORE__INITIAL__CAPACITY, - help = CliStrings.ALTER_DISK_STORE__INITIAL__CAPACITY__HELP) Integer initialCapacity, - @CliOption(key = CliStrings.ALTER_DISK_STORE__LOAD__FACTOR, - help = CliStrings.ALTER_DISK_STORE__LOAD__FACTOR__HELP) Float loadFactor, - @CliOption(key = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__ACTION, - help = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__ACTION__HELP) String lruEvictionAction, - @CliOption(key = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__ALGORITHM, - help = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__ALGORITHM__HELP) String lruEvictionAlgo, - @CliOption(key = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__LIMIT, - help = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__LIMIT__HELP) Integer lruEvictionLimit, - @CliOption(key = CliStrings.ALTER_DISK_STORE__OFF_HEAP, - help = CliStrings.ALTER_DISK_STORE__OFF_HEAP__HELP) Boolean offHeap, - @CliOption(key = CliStrings.ALTER_DISK_STORE__REMOVE, - help = CliStrings.ALTER_DISK_STORE__REMOVE__HELP, specifiedDefaultValue = "true", - unspecifiedDefaultValue = "false") boolean remove) { - - Result result; - - try { - File[] dirs = null; - - if (diskDirs != null) { - dirs = new File[diskDirs.length]; - for (int i = 0; i < diskDirs.length; i++) { - dirs[i] = new File((diskDirs[i])); - } - } - - if (regionName.equals(Region.SEPARATOR)) { - return ResultBuilder.createUserErrorResult(CliStrings.INVALID_REGION_NAME); - } - - if ((lruEvictionAlgo != null) || (lruEvictionAction != null) || (lruEvictionLimit != null) - || (concurrencyLevel != null) || (initialCapacity != null) || (loadFactor != null) - || (compressorClassName != null) || (offHeap != null) || (statisticsEnabled != null)) { - if (!remove) { - String lruEvictionLimitString = - lruEvictionLimit == null ? null : lruEvictionLimit.toString(); - String concurrencyLevelString = - concurrencyLevel == null ? null : concurrencyLevel.toString(); - String initialCapacityString = - initialCapacity == null ? null : initialCapacity.toString(); - String loadFactorString = loadFactor == null ? null : loadFactor.toString(); - String statisticsEnabledString = - statisticsEnabled == null ? null : statisticsEnabled.toString(); - String offHeapString = offHeap == null ? null : offHeap.toString(); - - if ("none".equals(compressorClassName)) { - compressorClassName = ""; - } - - String resultMessage = DiskStoreImpl.modifyRegion(diskStoreName, dirs, "/" + regionName, - lruEvictionAlgo, lruEvictionAction, lruEvictionLimitString, concurrencyLevelString, - initialCapacityString, loadFactorString, compressorClassName, statisticsEnabledString, - offHeapString, false); - - result = ResultBuilder.createInfoResult(resultMessage); - } else { - result = ResultBuilder.createParsingErrorResult( - "Cannot use the --remove=true parameter with any other parameters"); - } - } else { - if (remove) { - DiskStoreImpl.destroyRegion(diskStoreName, dirs, "/" + regionName); - result = ResultBuilder.createInfoResult("The region " + regionName - + " was successfully removed from the disk store " + diskStoreName); - } else { - // Please provide an option - result = ResultBuilder.createParsingErrorResult("Please provide a relevant parameter"); - } - } - // Catch the IllegalArgumentException thrown by the modifyDiskStore function and sent the - } catch (IllegalArgumentException e) { - String message = "Please check the parameters"; - message += "\n" + e.getMessage(); - result = ResultBuilder.createGemFireErrorResult(message); - } catch (IllegalStateException e) { - result = ResultBuilder.createGemFireErrorResult(e.getMessage()); - } catch (CacheExistsException e) { - // Indicates that the command is being used when a cache is open - result = ResultBuilder.createGemFireErrorResult("Cannot execute " - + CliStrings.ALTER_DISK_STORE + " when a cache exists (Offline command)"); - } catch (Exception e) { - result = createErrorResult(e.getMessage()); - } - return result; - } - - private Result createErrorResult(String message) { - ErrorResultData erd = ResultBuilder.createErrorResultData(); - erd.addLine(message); - return ResultBuilder.buildResult(erd); - } -} http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/AlterRegionCommand.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/AlterRegionCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/AlterRegionCommand.java deleted file mode 100644 index 0f9b5d8..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/AlterRegionCommand.java +++ /dev/null @@ -1,229 +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 java.util.List; -import java.util.Set; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.commons.lang.StringUtils; -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; - -import org.apache.geode.cache.ExpirationAttributes; -import org.apache.geode.cache.execute.ResultCollector; -import org.apache.geode.distributed.DistributedMember; -import org.apache.geode.internal.cache.InternalCache; -import org.apache.geode.management.cli.CliMetaData; -import org.apache.geode.management.cli.ConverterHint; -import org.apache.geode.management.cli.Result; -import org.apache.geode.management.internal.cli.CliUtil; -import org.apache.geode.management.internal.cli.LogWrapper; -import org.apache.geode.management.internal.cli.functions.CliFunctionResult; -import org.apache.geode.management.internal.cli.functions.RegionAlterFunction; -import org.apache.geode.management.internal.cli.functions.RegionFunctionArgs; -import org.apache.geode.management.internal.cli.i18n.CliStrings; -import org.apache.geode.management.internal.cli.result.ResultBuilder; -import org.apache.geode.management.internal.cli.result.TabularResultData; -import org.apache.geode.management.internal.configuration.domain.XmlEntity; - -public class AlterRegionCommand implements GfshCommand { - @CliCommand(value = CliStrings.ALTER_REGION, help = CliStrings.ALTER_REGION__HELP) - @CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_REGION) - public Result alterRegion( - @CliOption(key = CliStrings.ALTER_REGION__REGION, mandatory = true, - help = CliStrings.ALTER_REGION__REGION__HELP) String regionPath, - @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS}, - optionContext = ConverterHint.MEMBERGROUP, - help = CliStrings.ALTER_REGION__GROUP__HELP) String[] groups, - @CliOption(key = CliStrings.ALTER_REGION__ENTRYEXPIRATIONIDLETIME, - specifiedDefaultValue = "-1", - help = CliStrings.ALTER_REGION__ENTRYEXPIRATIONIDLETIME__HELP) Integer entryExpirationIdleTime, - @CliOption(key = CliStrings.ALTER_REGION__ENTRYEXPIRATIONIDLETIMEACTION, - specifiedDefaultValue = "INVALIDATE", - help = CliStrings.ALTER_REGION__ENTRYEXPIRATIONIDLETIMEACTION__HELP) String entryExpirationIdleTimeAction, - @CliOption(key = CliStrings.ALTER_REGION__ENTRYEXPIRATIONTIMETOLIVE, - specifiedDefaultValue = "-1", - help = CliStrings.ALTER_REGION__ENTRYEXPIRATIONTIMETOLIVE__HELP) Integer entryExpirationTTL, - @CliOption(key = CliStrings.ALTER_REGION__ENTRYEXPIRATIONTTLACTION, - specifiedDefaultValue = "INVALIDATE", - help = CliStrings.ALTER_REGION__ENTRYEXPIRATIONTTLACTION__HELP) String entryExpirationTTLAction, - @CliOption(key = CliStrings.ALTER_REGION__REGIONEXPIRATIONIDLETIME, - specifiedDefaultValue = "-1", - help = CliStrings.ALTER_REGION__REGIONEXPIRATIONIDLETIME__HELP) Integer regionExpirationIdleTime, - @CliOption(key = CliStrings.ALTER_REGION__REGIONEXPIRATIONIDLETIMEACTION, - specifiedDefaultValue = "INVALIDATE", - help = CliStrings.ALTER_REGION__REGIONEXPIRATIONIDLETIMEACTION__HELP) String regionExpirationIdleTimeAction, - @CliOption(key = CliStrings.ALTER_REGION__REGIONEXPIRATIONTTL, specifiedDefaultValue = "-1", - help = CliStrings.ALTER_REGION__REGIONEXPIRATIONTTL__HELP) Integer regionExpirationTTL, - @CliOption(key = CliStrings.ALTER_REGION__REGIONEXPIRATIONTTLACTION, - specifiedDefaultValue = "INVALIDATE", - help = CliStrings.ALTER_REGION__REGIONEXPIRATIONTTLACTION__HELP) String regionExpirationTTLAction, - @CliOption(key = CliStrings.ALTER_REGION__CACHELISTENER, specifiedDefaultValue = "", - help = CliStrings.ALTER_REGION__CACHELISTENER__HELP) String[] cacheListeners, - @CliOption(key = CliStrings.ALTER_REGION__CACHELOADER, specifiedDefaultValue = "", - help = CliStrings.ALTER_REGION__CACHELOADER__HELP) String cacheLoader, - @CliOption(key = CliStrings.ALTER_REGION__CACHEWRITER, specifiedDefaultValue = "", - help = CliStrings.ALTER_REGION__CACHEWRITER__HELP) String cacheWriter, - @CliOption(key = CliStrings.ALTER_REGION__ASYNCEVENTQUEUEID, specifiedDefaultValue = "", - help = CliStrings.ALTER_REGION__ASYNCEVENTQUEUEID__HELP) String[] asyncEventQueueIds, - @CliOption(key = CliStrings.ALTER_REGION__GATEWAYSENDERID, specifiedDefaultValue = "", - help = CliStrings.ALTER_REGION__GATEWAYSENDERID__HELP) String[] gatewaySenderIds, - @CliOption(key = CliStrings.ALTER_REGION__CLONINGENABLED, specifiedDefaultValue = "false", - help = CliStrings.ALTER_REGION__CLONINGENABLED__HELP) Boolean cloningEnabled, - @CliOption(key = CliStrings.ALTER_REGION__EVICTIONMAX, specifiedDefaultValue = "0", - help = CliStrings.ALTER_REGION__EVICTIONMAX__HELP) Integer evictionMax) { - Result result; - AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>(); - - getSecurityService().authorizeRegionManage(regionPath); - - try { - InternalCache cache = getCache(); - - if (groups != null) { - RegionCommandsUtils.validateGroups(cache, groups); - } - - RegionFunctionArgs.ExpirationAttrs entryIdle = null; - if (entryExpirationIdleTime != null || entryExpirationIdleTimeAction != null) { - if (entryExpirationIdleTime != null && entryExpirationIdleTime == -1) { - entryExpirationIdleTime = ExpirationAttributes.DEFAULT.getTimeout(); - } - if (CliMetaData.ANNOTATION_DEFAULT_VALUE.equals(entryExpirationIdleTimeAction)) { - entryExpirationIdleTimeAction = ExpirationAttributes.DEFAULT.getAction().toString(); - } - entryIdle = new RegionFunctionArgs.ExpirationAttrs( - RegionFunctionArgs.ExpirationAttrs.ExpirationFor.ENTRY_IDLE, entryExpirationIdleTime, - entryExpirationIdleTimeAction); - } - RegionFunctionArgs.ExpirationAttrs entryTTL = null; - if (entryExpirationTTL != null || entryExpirationTTLAction != null) { - if (entryExpirationTTL != null && entryExpirationTTL == -1) { - entryExpirationTTL = ExpirationAttributes.DEFAULT.getTimeout(); - } - if (CliMetaData.ANNOTATION_DEFAULT_VALUE.equals(entryExpirationTTLAction)) { - entryExpirationTTLAction = ExpirationAttributes.DEFAULT.getAction().toString(); - } - entryTTL = new RegionFunctionArgs.ExpirationAttrs( - RegionFunctionArgs.ExpirationAttrs.ExpirationFor.ENTRY_TTL, entryExpirationTTL, - entryExpirationTTLAction); - } - RegionFunctionArgs.ExpirationAttrs regionIdle = null; - if (regionExpirationIdleTime != null || regionExpirationIdleTimeAction != null) { - if (regionExpirationIdleTime != null && regionExpirationIdleTime == -1) { - regionExpirationIdleTime = ExpirationAttributes.DEFAULT.getTimeout(); - } - if (CliMetaData.ANNOTATION_DEFAULT_VALUE.equals(regionExpirationIdleTimeAction)) { - regionExpirationIdleTimeAction = ExpirationAttributes.DEFAULT.getAction().toString(); - } - regionIdle = new RegionFunctionArgs.ExpirationAttrs( - RegionFunctionArgs.ExpirationAttrs.ExpirationFor.REGION_IDLE, regionExpirationIdleTime, - regionExpirationIdleTimeAction); - } - RegionFunctionArgs.ExpirationAttrs regionTTL = null; - if (regionExpirationTTL != null || regionExpirationTTLAction != null) { - if (regionExpirationTTL != null && regionExpirationTTL == -1) { - regionExpirationTTL = ExpirationAttributes.DEFAULT.getTimeout(); - } - if (CliMetaData.ANNOTATION_DEFAULT_VALUE.equals(regionExpirationTTLAction)) { - regionExpirationTTLAction = ExpirationAttributes.DEFAULT.getAction().toString(); - } - regionTTL = new RegionFunctionArgs.ExpirationAttrs( - RegionFunctionArgs.ExpirationAttrs.ExpirationFor.REGION_TTL, regionExpirationTTL, - regionExpirationTTLAction); - } - - cacheLoader = convertDefaultValue(cacheLoader, StringUtils.EMPTY); - cacheWriter = convertDefaultValue(cacheWriter, StringUtils.EMPTY); - - RegionFunctionArgs regionFunctionArgs; - regionFunctionArgs = new RegionFunctionArgs(regionPath, null, null, false, null, null, null, - entryIdle, entryTTL, regionIdle, regionTTL, null, null, null, null, cacheListeners, - cacheLoader, cacheWriter, asyncEventQueueIds, gatewaySenderIds, null, cloningEnabled, - null, null, null, null, null, null, null, null, evictionMax, null, null, null, null); - - Set<String> cacheListenersSet = regionFunctionArgs.getCacheListeners(); - if (cacheListenersSet != null && !cacheListenersSet.isEmpty()) { - for (String cacheListener : cacheListenersSet) { - if (!RegionCommandsUtils.isClassNameValid(cacheListener)) { - throw new IllegalArgumentException(CliStrings.format( - CliStrings.ALTER_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_CACHELISTENER_0_IS_INVALID, - new Object[] {cacheListener})); - } - } - } - - if (cacheLoader != null && !RegionCommandsUtils.isClassNameValid(cacheLoader)) { - throw new IllegalArgumentException(CliStrings.format( - CliStrings.ALTER_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_CACHELOADER_0_IS_INVALID, - new Object[] {cacheLoader})); - } - - if (cacheWriter != null && !RegionCommandsUtils.isClassNameValid(cacheWriter)) { - throw new IllegalArgumentException(CliStrings.format( - CliStrings.ALTER_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_CACHEWRITER_0_IS_INVALID, - new Object[] {cacheWriter})); - } - - if (evictionMax != null && evictionMax < 0) { - throw new IllegalArgumentException(CliStrings.format( - CliStrings.ALTER_REGION__MSG__SPECIFY_POSITIVE_INT_FOR_EVICTIONMAX_0_IS_NOT_VALID, - new Object[] {evictionMax})); - } - - Set<DistributedMember> targetMembers = CliUtil.findMembers(groups, null); - - if (targetMembers.isEmpty()) { - return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE); - } - - ResultCollector<?, ?> resultCollector = - CliUtil.executeFunction(new RegionAlterFunction(), regionFunctionArgs, targetMembers); - List<CliFunctionResult> regionAlterResults = - (List<CliFunctionResult>) resultCollector.getResult(); - - TabularResultData tabularResultData = ResultBuilder.createTabularResultData(); - final String errorPrefix = "ERROR: "; - for (CliFunctionResult regionAlterResult : regionAlterResults) { - boolean success = regionAlterResult.isSuccessful(); - tabularResultData.accumulate("Member", regionAlterResult.getMemberIdOrName()); - if (success) { - tabularResultData.accumulate("Status", regionAlterResult.getMessage()); - xmlEntity.set(regionAlterResult.getXmlEntity()); - } else { - tabularResultData.accumulate("Status", errorPrefix + regionAlterResult.getMessage()); - tabularResultData.setStatus(Result.Status.ERROR); - } - } - result = ResultBuilder.buildResult(tabularResultData); - } catch (IllegalArgumentException | IllegalStateException e) { - LogWrapper.getInstance().info(e.getMessage()); - result = ResultBuilder.createUserErrorResult(e.getMessage()); - } catch (RuntimeException e) { - LogWrapper.getInstance().info(e.getMessage(), e); - result = ResultBuilder.createGemFireErrorResult(e.getMessage()); - } - - if (xmlEntity.get() != null) { - persistClusterConfiguration(result, - () -> getSharedConfiguration().addXmlEntity(xmlEntity.get(), groups)); - } - return result; - } - - - -} http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/AlterRuntimeConfigCommand.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/AlterRuntimeConfigCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/AlterRuntimeConfigCommand.java deleted file mode 100644 index 4415968..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/AlterRuntimeConfigCommand.java +++ /dev/null @@ -1,246 +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 static org.apache.geode.distributed.ConfigurationProperties.STATISTIC_SAMPLING_ENABLED; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; -import java.util.TreeSet; - -import org.apache.commons.lang.StringUtils; -import org.apache.logging.log4j.Logger; -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; - -import org.apache.geode.cache.execute.ResultCollector; -import org.apache.geode.distributed.DistributedMember; -import org.apache.geode.internal.cache.xmlcache.CacheXml; -import org.apache.geode.internal.logging.LogService; -import org.apache.geode.internal.logging.log4j.LogLevel; -import org.apache.geode.management.cli.CliMetaData; -import org.apache.geode.management.cli.ConverterHint; -import org.apache.geode.management.cli.Result; -import org.apache.geode.management.internal.cli.AbstractCliAroundInterceptor; -import org.apache.geode.management.internal.cli.CliUtil; -import org.apache.geode.management.internal.cli.GfshParseResult; -import org.apache.geode.management.internal.cli.functions.AlterRuntimeConfigFunction; -import org.apache.geode.management.internal.cli.functions.CliFunctionResult; -import org.apache.geode.management.internal.cli.i18n.CliStrings; -import org.apache.geode.management.internal.cli.result.ResultBuilder; -import org.apache.geode.management.internal.configuration.domain.XmlEntity; -import org.apache.geode.management.internal.security.ResourceOperation; -import org.apache.geode.security.ResourcePermission; - -public class AlterRuntimeConfigCommand implements GfshCommand { - private final AlterRuntimeConfigFunction alterRunTimeConfigFunction = - new AlterRuntimeConfigFunction(); - private static Logger logger = LogService.getLogger(); - - @CliCommand(value = {CliStrings.ALTER_RUNTIME_CONFIG}, - help = CliStrings.ALTER_RUNTIME_CONFIG__HELP) - @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_CONFIG}, - interceptor = "org.apache.geode.management.internal.cli.commands.AlterRuntimeConfigCommand$AlterRuntimeInterceptor") - @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, - operation = ResourcePermission.Operation.MANAGE) - public Result alterRuntimeConfig( - @CliOption(key = {CliStrings.MEMBER, CliStrings.MEMBERS}, - optionContext = ConverterHint.ALL_MEMBER_IDNAME, - help = CliStrings.ALTER_RUNTIME_CONFIG__MEMBER__HELP) String[] memberNameOrId, - @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS}, - optionContext = ConverterHint.MEMBERGROUP, - help = CliStrings.ALTER_RUNTIME_CONFIG__GROUP__HELP) String[] group, - @CliOption(key = {CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__DISK__SPACE__LIMIT}, - help = CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__DISK__SPACE__LIMIT__HELP) Integer archiveDiskSpaceLimit, - @CliOption(key = {CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__FILE__SIZE__LIMIT}, - help = CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__FILE__SIZE__LIMIT__HELP) Integer archiveFileSizeLimit, - @CliOption(key = {CliStrings.ALTER_RUNTIME_CONFIG__LOG__DISK__SPACE__LIMIT}, - help = CliStrings.ALTER_RUNTIME_CONFIG__LOG__DISK__SPACE__LIMIT__HELP) Integer logDiskSpaceLimit, - @CliOption(key = {CliStrings.ALTER_RUNTIME_CONFIG__LOG__FILE__SIZE__LIMIT}, - help = CliStrings.ALTER_RUNTIME_CONFIG__LOG__FILE__SIZE__LIMIT__HELP) Integer logFileSizeLimit, - @CliOption(key = {CliStrings.ALTER_RUNTIME_CONFIG__LOG__LEVEL}, - optionContext = ConverterHint.LOG_LEVEL, - help = CliStrings.ALTER_RUNTIME_CONFIG__LOG__LEVEL__HELP) String logLevel, - @CliOption(key = {CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__ARCHIVE__FILE}, - help = CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__ARCHIVE__FILE__HELP) String statisticArchiveFile, - @CliOption(key = {CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLE__RATE}, - help = CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLE__RATE__HELP) Integer statisticSampleRate, - @CliOption(key = {CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLING__ENABLED}, - help = CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLING__ENABLED__HELP) Boolean statisticSamplingEnabled, - @CliOption(key = {CliStrings.ALTER_RUNTIME_CONFIG__COPY__ON__READ}, - specifiedDefaultValue = "false", - help = CliStrings.ALTER_RUNTIME_CONFIG__COPY__ON__READ__HELP) Boolean setCopyOnRead, - @CliOption(key = {CliStrings.ALTER_RUNTIME_CONFIG__LOCK__LEASE}, - help = CliStrings.ALTER_RUNTIME_CONFIG__LOCK__LEASE__HELP) Integer lockLease, - @CliOption(key = {CliStrings.ALTER_RUNTIME_CONFIG__LOCK__TIMEOUT}, - help = CliStrings.ALTER_RUNTIME_CONFIG__LOCK__TIMEOUT__HELP) Integer lockTimeout, - @CliOption(key = {CliStrings.ALTER_RUNTIME_CONFIG__MESSAGE__SYNC__INTERVAL}, - help = CliStrings.ALTER_RUNTIME_CONFIG__MESSAGE__SYNC__INTERVAL__HELP) Integer messageSyncInterval, - @CliOption(key = {CliStrings.ALTER_RUNTIME_CONFIG__SEARCH__TIMEOUT}, - help = CliStrings.ALTER_RUNTIME_CONFIG__SEARCH__TIMEOUT__HELP) Integer searchTimeout) { - - Map<String, String> runTimeDistributionConfigAttributes = new HashMap<>(); - Map<String, String> rumTimeCacheAttributes = new HashMap<>(); - Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrId); - - if (targetMembers.isEmpty()) { - return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE); - } - - if (archiveDiskSpaceLimit != null) { - runTimeDistributionConfigAttributes.put( - CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__DISK__SPACE__LIMIT, - archiveDiskSpaceLimit.toString()); - } - - if (archiveFileSizeLimit != null) { - runTimeDistributionConfigAttributes.put( - CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__FILE__SIZE__LIMIT, - archiveFileSizeLimit.toString()); - } - - if (logDiskSpaceLimit != null) { - runTimeDistributionConfigAttributes.put( - CliStrings.ALTER_RUNTIME_CONFIG__LOG__DISK__SPACE__LIMIT, logDiskSpaceLimit.toString()); - } - - if (logFileSizeLimit != null) { - runTimeDistributionConfigAttributes.put( - CliStrings.ALTER_RUNTIME_CONFIG__LOG__FILE__SIZE__LIMIT, logFileSizeLimit.toString()); - } - - if (logLevel != null && !logLevel.isEmpty()) { - runTimeDistributionConfigAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__LOG__LEVEL, - logLevel); - } - - if (statisticArchiveFile != null && !statisticArchiveFile.isEmpty()) { - runTimeDistributionConfigAttributes - .put(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__ARCHIVE__FILE, statisticArchiveFile); - } - - if (statisticSampleRate != null) { - runTimeDistributionConfigAttributes.put( - CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLE__RATE, statisticSampleRate.toString()); - } - - if (statisticSamplingEnabled != null) { - runTimeDistributionConfigAttributes.put(STATISTIC_SAMPLING_ENABLED, - statisticSamplingEnabled.toString()); - } - - - // Attributes that are set on the cache. - if (setCopyOnRead != null) { - rumTimeCacheAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__COPY__ON__READ, - setCopyOnRead.toString()); - } - - if (lockLease != null && lockLease > 0 && lockLease < Integer.MAX_VALUE) { - rumTimeCacheAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__LOCK__LEASE, - lockLease.toString()); - } - - if (lockTimeout != null && lockTimeout > 0 && lockTimeout < Integer.MAX_VALUE) { - rumTimeCacheAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__LOCK__TIMEOUT, - lockTimeout.toString()); - } - - if (messageSyncInterval != null && messageSyncInterval > 0 - && messageSyncInterval < Integer.MAX_VALUE) { - rumTimeCacheAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__MESSAGE__SYNC__INTERVAL, - messageSyncInterval.toString()); - } - - if (searchTimeout != null && searchTimeout > 0 && searchTimeout < Integer.MAX_VALUE) { - rumTimeCacheAttributes.put(CliStrings.ALTER_RUNTIME_CONFIG__SEARCH__TIMEOUT, - searchTimeout.toString()); - } - - if (runTimeDistributionConfigAttributes.isEmpty() && rumTimeCacheAttributes.isEmpty()) { - return ResultBuilder - .createUserErrorResult(CliStrings.ALTER_RUNTIME_CONFIG__RELEVANT__OPTION__MESSAGE); - } - - Map<String, String> allRunTimeAttributes = new HashMap<>(); - allRunTimeAttributes.putAll(runTimeDistributionConfigAttributes); - allRunTimeAttributes.putAll(rumTimeCacheAttributes); - - ResultCollector<?, ?> rc = - CliUtil.executeFunction(alterRunTimeConfigFunction, allRunTimeAttributes, targetMembers); - List<CliFunctionResult> results = CliFunctionResult.cleanResults((List<?>) rc.getResult()); - Set<String> successfulMembers = new TreeSet<>(); - Set<String> errorMessages = new TreeSet<>(); - - for (CliFunctionResult result : results) { - if (result.getThrowable() != null) { - logger.info("Function failed: " + result.getThrowable()); - errorMessages.add(result.getThrowable().getMessage()); - } else { - successfulMembers.add(result.getMemberIdOrName()); - } - } - final String lineSeparator = System.getProperty("line.separator"); - if (!successfulMembers.isEmpty()) { - StringBuilder successMessageBuilder = new StringBuilder(); - - successMessageBuilder.append(CliStrings.ALTER_RUNTIME_CONFIG__SUCCESS__MESSAGE); - successMessageBuilder.append(lineSeparator); - - for (String member : successfulMembers) { - successMessageBuilder.append(member); - successMessageBuilder.append(lineSeparator); - } - - Properties properties = new Properties(); - properties.putAll(runTimeDistributionConfigAttributes); - - Result result = ResultBuilder.createInfoResult(successMessageBuilder.toString()); - - // Set the Cache attributes to be modified - final XmlEntity xmlEntity = XmlEntity.builder().withType(CacheXml.CACHE) - .withAttributes(rumTimeCacheAttributes).build(); - persistClusterConfiguration(result, - () -> getSharedConfiguration().modifyXmlAndProperties(properties, xmlEntity, group)); - return result; - } else { - StringBuilder errorMessageBuilder = new StringBuilder(); - errorMessageBuilder.append("Following errors occurred while altering runtime config"); - errorMessageBuilder.append(lineSeparator); - - for (String errorMessage : errorMessages) { - errorMessageBuilder.append(errorMessage); - errorMessageBuilder.append(lineSeparator); - } - return ResultBuilder.createUserErrorResult(errorMessageBuilder.toString()); - } - } - - public static class AlterRuntimeInterceptor extends AbstractCliAroundInterceptor { - @Override - public Result preExecution(GfshParseResult parseResult) { - Map<String, String> arguments = parseResult.getParamValueStrings(); - // validate log level - String logLevel = arguments.get("log-level"); - if (StringUtils.isNotBlank(logLevel) && (LogLevel.getLevel(logLevel) == null)) { - return ResultBuilder.createUserErrorResult("Invalid log level: " + logLevel); - } - return ResultBuilder.createInfoResult(""); - } - } -} http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/AlterRuntimeInterceptor.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/AlterRuntimeInterceptor.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/AlterRuntimeInterceptor.java deleted file mode 100644 index 37d4dbb..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/AlterRuntimeInterceptor.java +++ /dev/null @@ -1,39 +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 java.util.Map; - -import org.apache.commons.lang.StringUtils; - -import org.apache.geode.internal.logging.log4j.LogLevel; -import org.apache.geode.management.cli.Result; -import org.apache.geode.management.internal.cli.AbstractCliAroundInterceptor; -import org.apache.geode.management.internal.cli.GfshParseResult; -import org.apache.geode.management.internal.cli.result.ResultBuilder; - -public class AlterRuntimeInterceptor extends AbstractCliAroundInterceptor { - @Override - public Result preExecution(GfshParseResult parseResult) { - Map<String, String> arguments = parseResult.getParamValueStrings(); - // validate log level - String logLevel = arguments.get("log-level"); - if (StringUtils.isNotBlank(logLevel) && (LogLevel.getLevel(logLevel) == null)) { - return ResultBuilder.createUserErrorResult("Invalid log level: " + logLevel); - } - return ResultBuilder.createInfoResult(""); - } -} http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/BackupDiskStoreCommand.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/BackupDiskStoreCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/BackupDiskStoreCommand.java deleted file mode 100644 index 6fc5df1..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/BackupDiskStoreCommand.java +++ /dev/null @@ -1,142 +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 java.io.File; -import java.util.Map; -import java.util.Set; - -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; - -import org.apache.geode.admin.BackupStatus; -import org.apache.geode.admin.internal.AdminDistributedSystemImpl; -import org.apache.geode.cache.persistence.PersistentID; -import org.apache.geode.distributed.DistributedMember; -import org.apache.geode.distributed.internal.DM; -import org.apache.geode.internal.cache.InternalCache; -import org.apache.geode.management.cli.CliMetaData; -import org.apache.geode.management.cli.Result; -import org.apache.geode.management.internal.cli.i18n.CliStrings; -import org.apache.geode.management.internal.cli.result.CompositeResultData; -import org.apache.geode.management.internal.cli.result.ResultBuilder; -import org.apache.geode.management.internal.cli.result.TabularResultData; -import org.apache.geode.management.internal.security.ResourceOperation; -import org.apache.geode.security.ResourcePermission; - -public class BackupDiskStoreCommand implements GfshCommand { - /** - * Internally, we also verify the resource operation permissions CLUSTER:WRITE:DISK if the region - * is persistent - */ - @CliCommand(value = CliStrings.BACKUP_DISK_STORE, help = CliStrings.BACKUP_DISK_STORE__HELP) - @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_DISKSTORE}) - @ResourceOperation(resource = ResourcePermission.Resource.DATA, - operation = ResourcePermission.Operation.READ) - public Result backupDiskStore( - @CliOption(key = CliStrings.BACKUP_DISK_STORE__DISKDIRS, - help = CliStrings.BACKUP_DISK_STORE__DISKDIRS__HELP, mandatory = true) String targetDir, - @CliOption(key = CliStrings.BACKUP_DISK_STORE__BASELINEDIR, - help = CliStrings.BACKUP_DISK_STORE__BASELINEDIR__HELP) String baselineDir) { - - getSecurityService().authorize(ResourcePermission.Resource.CLUSTER, - ResourcePermission.Operation.WRITE, ResourcePermission.Target.DISK); - Result result; - try { - InternalCache cache = getCache(); - DM dm = cache.getDistributionManager(); - BackupStatus backupStatus; - - if (baselineDir != null && !baselineDir.isEmpty()) { - backupStatus = AdminDistributedSystemImpl.backupAllMembers(dm, new File(targetDir), - new File(baselineDir)); - } else { - backupStatus = AdminDistributedSystemImpl.backupAllMembers(dm, new File(targetDir), null); - } - - Map<DistributedMember, Set<PersistentID>> backedupMemberDiskstoreMap = - backupStatus.getBackedUpDiskStores(); - - Set<DistributedMember> backedupMembers = backedupMemberDiskstoreMap.keySet(); - CompositeResultData crd = ResultBuilder.createCompositeResultData(); - - if (!backedupMembers.isEmpty()) { - CompositeResultData.SectionResultData backedupDiskStoresSection = crd.addSection(); - backedupDiskStoresSection.setHeader(CliStrings.BACKUP_DISK_STORE_MSG_BACKED_UP_DISK_STORES); - TabularResultData backedupDiskStoresTable = backedupDiskStoresSection.addTable(); - - for (DistributedMember member : backedupMembers) { - Set<PersistentID> backedupDiskStores = backedupMemberDiskstoreMap.get(member); - boolean printMember = true; - String memberName = member.getName(); - - if (memberName == null || memberName.isEmpty()) { - memberName = member.getId(); - } - for (PersistentID persistentId : backedupDiskStores) { - if (persistentId != null) { - - String UUID = persistentId.getUUID().toString(); - String hostName = persistentId.getHost().getHostName(); - String directory = persistentId.getDirectory(); - - if (printMember) { - writeToBackupDiskStoreTable(backedupDiskStoresTable, memberName, UUID, hostName, - directory); - printMember = false; - } else { - writeToBackupDiskStoreTable(backedupDiskStoresTable, "", UUID, hostName, directory); - } - } - } - } - } else { - CompositeResultData.SectionResultData noMembersBackedUp = crd.addSection(); - noMembersBackedUp.setHeader(CliStrings.BACKUP_DISK_STORE_MSG_NO_DISKSTORES_BACKED_UP); - } - - Set<PersistentID> offlineDiskStores = backupStatus.getOfflineDiskStores(); - - if (!offlineDiskStores.isEmpty()) { - CompositeResultData.SectionResultData offlineDiskStoresSection = crd.addSection(); - TabularResultData offlineDiskStoresTable = offlineDiskStoresSection.addTable(); - - offlineDiskStoresSection.setHeader(CliStrings.BACKUP_DISK_STORE_MSG_OFFLINE_DISK_STORES); - for (PersistentID offlineDiskStore : offlineDiskStores) { - offlineDiskStoresTable.accumulate(CliStrings.BACKUP_DISK_STORE_MSG_UUID, - offlineDiskStore.getUUID().toString()); - offlineDiskStoresTable.accumulate(CliStrings.BACKUP_DISK_STORE_MSG_HOST, - offlineDiskStore.getHost().getHostName()); - offlineDiskStoresTable.accumulate(CliStrings.BACKUP_DISK_STORE_MSG_DIRECTORY, - offlineDiskStore.getDirectory()); - } - } - result = ResultBuilder.buildResult(crd); - - } catch (Exception e) { - result = ResultBuilder.createGemFireErrorResult(e.getMessage()); - } - return result; - } - - private void writeToBackupDiskStoreTable(TabularResultData backedupDiskStoreTable, - String memberId, String UUID, String host, String directory) { - backedupDiskStoreTable.accumulate(CliStrings.BACKUP_DISK_STORE_MSG_MEMBER, memberId); - backedupDiskStoreTable.accumulate(CliStrings.BACKUP_DISK_STORE_MSG_UUID, UUID); - backedupDiskStoreTable.accumulate(CliStrings.BACKUP_DISK_STORE_MSG_DIRECTORY, directory); - backedupDiskStoreTable.accumulate(CliStrings.BACKUP_DISK_STORE_MSG_HOST, host); - } -} http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommand.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommand.java deleted file mode 100644 index 823c113..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ChangeLogLevelCommand.java +++ /dev/null @@ -1,163 +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 java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.commons.lang.StringUtils; -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; - -import org.apache.geode.LogWriter; -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.internal.cache.GemFireCacheImpl; -import org.apache.geode.internal.cache.InternalCache; -import org.apache.geode.internal.logging.log4j.LogLevel; -import org.apache.geode.management.cli.CliMetaData; -import org.apache.geode.management.cli.ConverterHint; -import org.apache.geode.management.cli.Result; -import org.apache.geode.management.internal.cli.AbstractCliAroundInterceptor; -import org.apache.geode.management.internal.cli.CliUtil; -import org.apache.geode.management.internal.cli.GfshParseResult; -import org.apache.geode.management.internal.cli.LogWrapper; -import org.apache.geode.management.internal.cli.functions.ChangeLogLevelFunction; -import org.apache.geode.management.internal.cli.i18n.CliStrings; -import org.apache.geode.management.internal.cli.result.CompositeResultData; -import org.apache.geode.management.internal.cli.result.ResultBuilder; -import org.apache.geode.management.internal.cli.result.TabularResultData; -import org.apache.geode.management.internal.security.ResourceOperation; -import org.apache.geode.security.ResourcePermission; - -public class ChangeLogLevelCommand implements GfshCommand { - @CliCommand(value = CliStrings.CHANGE_LOGLEVEL, help = CliStrings.CHANGE_LOGLEVEL__HELP) - @CliMetaData(relatedTopic = {CliStrings.TOPIC_LOGS}, - interceptor = "org.apache.geode.management.internal.cli.commands.ChangeLogLevelCommand$ChangeLogLevelCommandInterceptor") - @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, - operation = ResourcePermission.Operation.WRITE) - public Result changeLogLevel( - @CliOption(key = {CliStrings.MEMBER, CliStrings.MEMBERS}, - help = CliStrings.CHANGE_LOGLEVEL__MEMBER__HELP) String[] memberIds, - @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS}, unspecifiedDefaultValue = "", - help = CliStrings.CHANGE_LOGLEVEL__GROUPS__HELP) String[] grps, - @CliOption(key = CliStrings.CHANGE_LOGLEVEL__LOGLEVEL, - optionContext = ConverterHint.LOG_LEVEL, mandatory = true, unspecifiedDefaultValue = "", - help = CliStrings.CHANGE_LOGLEVEL__LOGLEVEL__HELP) String logLevel) { - try { - if ((memberIds == null || memberIds.length == 0) && (grps == null || grps.length == 0)) { - return ResultBuilder - .createUserErrorResult(CliStrings.CHANGE_LOGLEVEL__MSG__SPECIFY_GRP_OR_MEMBER); - } - - InternalCache cache = GemFireCacheImpl.getInstance(); - LogWriter logger = cache.getLogger(); - - Set<DistributedMember> dsMembers = new HashSet<>(); - Set<DistributedMember> ds = CliUtil.getAllMembers(cache); - - if (grps != null && grps.length > 0) { - for (String grp : grps) { - dsMembers.addAll(cache.getDistributedSystem().getGroupMembers(grp)); - } - } - - if (memberIds != null && memberIds.length > 0) { - for (String member : memberIds) { - for (DistributedMember mem : ds) { - if (mem.getName() != null - && (mem.getName().equals(member) || mem.getId().equals(member))) { - dsMembers.add(mem); - break; - } - } - } - } - - if (dsMembers.size() == 0) { - return ResultBuilder.createGemFireErrorResult(CliStrings.CHANGE_LOGLEVEL__MSG_NO_MEMBERS); - } - - Function logFunction = new ChangeLogLevelFunction(); - FunctionService.registerFunction(logFunction); - Object[] functionArgs = new Object[1]; - functionArgs[0] = logLevel; - - CompositeResultData compositeResultData = ResultBuilder.createCompositeResultData(); - CompositeResultData.SectionResultData section = compositeResultData.addSection("section"); - TabularResultData resultTable = section.addTable("ChangeLogLevel"); - resultTable = resultTable.setHeader("Summary"); - - Execution execution = FunctionService.onMembers(dsMembers).setArguments(functionArgs); - if (execution == null) { - return ResultBuilder.createUserErrorResult(CliStrings.CHANGE_LOGLEVEL__MSG__CANNOT_EXECUTE); - } - List<?> resultList = (List<?>) execution.execute(logFunction).getResult(); - - for (Object object : resultList) { - try { - if (object instanceof Throwable) { - logger.warning( - "Exception in ChangeLogLevelFunction " + ((Throwable) object).getMessage(), - ((Throwable) object)); - continue; - } - - if (object != null) { - Map<String, String> resultMap = (Map<String, String>) object; - Map.Entry<String, String> entry = resultMap.entrySet().iterator().next(); - - if (entry.getValue().contains("ChangeLogLevelFunction exception")) { - resultTable.accumulate(CliStrings.CHANGE_LOGLEVEL__COLUMN_MEMBER, entry.getKey()); - resultTable.accumulate(CliStrings.CHANGE_LOGLEVEL__COLUMN_STATUS, "false"); - } else { - resultTable.accumulate(CliStrings.CHANGE_LOGLEVEL__COLUMN_MEMBER, entry.getKey()); - resultTable.accumulate(CliStrings.CHANGE_LOGLEVEL__COLUMN_STATUS, "true"); - } - - } - } catch (Exception ex) { - LogWrapper.getInstance().warning("change log level command exception " + ex); - } - } - - Result result = ResultBuilder.buildResult(compositeResultData); - logger.info("change log-level command result=" + result); - return result; - } catch (Exception ex) { - GemFireCacheImpl.getInstance().getLogger().error("GFSH Changeloglevel exception: " + ex); - return ResultBuilder.createUserErrorResult(ex.getMessage()); - } - } - - public static class ChangeLogLevelCommandInterceptor extends AbstractCliAroundInterceptor { - @Override - public Result preExecution(GfshParseResult parseResult) { - Map<String, String> arguments = parseResult.getParamValueStrings(); - // validate log level - String logLevel = arguments.get("loglevel"); - if (StringUtils.isBlank(logLevel) || LogLevel.getLevel(logLevel) == null) { - return ResultBuilder.createUserErrorResult("Invalid log level: " + logLevel); - } - - return ResultBuilder.createInfoResult(""); - } - } -} http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ClearDefinedIndexesCommand.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ClearDefinedIndexesCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ClearDefinedIndexesCommand.java deleted file mode 100644 index 2795bf0..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ClearDefinedIndexesCommand.java +++ /dev/null @@ -1,40 +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.springframework.shell.core.annotation.CliCommand; - -import org.apache.geode.management.cli.CliMetaData; -import org.apache.geode.management.cli.Result; -import org.apache.geode.management.internal.cli.i18n.CliStrings; -import org.apache.geode.management.internal.cli.result.InfoResultData; -import org.apache.geode.management.internal.cli.result.ResultBuilder; -import org.apache.geode.management.internal.security.ResourceOperation; -import org.apache.geode.security.ResourcePermission; - -public class ClearDefinedIndexesCommand implements GfshCommand { - @CliCommand(value = CliStrings.CLEAR_DEFINED_INDEXES, help = CliStrings.CLEAR_DEFINED__HELP) - @CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA}) - @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, - operation = ResourcePermission.Operation.MANAGE, target = ResourcePermission.Target.QUERY) - // TODO : Add optionContext for indexName - public Result clearDefinedIndexes() { - IndexDefinition.indexDefinitions.clear(); - final InfoResultData infoResult = ResultBuilder.createInfoResultData(); - infoResult.addLine(CliStrings.CLEAR_DEFINED_INDEX__SUCCESS__MSG); - return ResultBuilder.buildResult(infoResult); - } -} http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CloseDurableCQsCommand.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CloseDurableCQsCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CloseDurableCQsCommand.java deleted file mode 100644 index 61dd914..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CloseDurableCQsCommand.java +++ /dev/null @@ -1,83 +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 java.util.List; -import java.util.Set; - -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; - -import org.apache.geode.cache.execute.ResultCollector; -import org.apache.geode.distributed.DistributedMember; -import org.apache.geode.management.cli.CliMetaData; -import org.apache.geode.management.cli.ConverterHint; -import org.apache.geode.management.cli.Result; -import org.apache.geode.management.internal.cli.CliUtil; -import org.apache.geode.management.internal.cli.domain.MemberResult; -import org.apache.geode.management.internal.cli.functions.CloseDurableCqFunction; -import org.apache.geode.management.internal.cli.i18n.CliStrings; -import org.apache.geode.management.internal.cli.result.ResultBuilder; -import org.apache.geode.management.internal.security.ResourceOperation; -import org.apache.geode.security.ResourcePermission; - -public class CloseDurableCQsCommand implements GfshCommand { - DurableClientCommandsResultBuilder builder = new DurableClientCommandsResultBuilder(); - - @CliCommand(value = CliStrings.CLOSE_DURABLE_CQS, help = CliStrings.CLOSE_DURABLE_CQS__HELP) - @CliMetaData() - @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, - operation = ResourcePermission.Operation.MANAGE, target = ResourcePermission.Target.QUERY) - public Result closeDurableCqs(@CliOption(key = CliStrings.CLOSE_DURABLE_CQS__DURABLE__CLIENT__ID, - mandatory = true, - help = CliStrings.CLOSE_DURABLE_CQS__DURABLE__CLIENT__ID__HELP) final String durableClientId, - - @CliOption(key = CliStrings.CLOSE_DURABLE_CQS__NAME, mandatory = true, - help = CliStrings.CLOSE_DURABLE_CQS__NAME__HELP) final String cqName, - - @CliOption(key = {CliStrings.MEMBER, CliStrings.MEMBERS}, - help = CliStrings.CLOSE_DURABLE_CQS__MEMBER__HELP, - optionContext = ConverterHint.MEMBERIDNAME) final String[] memberNameOrId, - - @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS}, - help = CliStrings.CLOSE_DURABLE_CQS__GROUP__HELP, - optionContext = ConverterHint.MEMBERGROUP) final String[] group) { - Result result; - try { - Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrId); - - if (targetMembers.isEmpty()) { - return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE); - } - - String[] params = new String[2]; - params[0] = durableClientId; - params[1] = cqName; - - final ResultCollector<?, ?> rc = - CliUtil.executeFunction(new CloseDurableCqFunction(), params, targetMembers); - final List<MemberResult> results = (List<MemberResult>) rc.getResult(); - String failureHeader = - CliStrings.format(CliStrings.CLOSE_DURABLE_CQS__FAILURE__HEADER, cqName, durableClientId); - String successHeader = - CliStrings.format(CliStrings.CLOSE_DURABLE_CQS__SUCCESS, cqName, durableClientId); - result = builder.buildResult(results, successHeader, failureHeader); - } catch (Exception e) { - result = ResultBuilder.createGemFireErrorResult(e.getMessage()); - } - return result; - } -} http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CloseDurableClientCommand.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CloseDurableClientCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CloseDurableClientCommand.java deleted file mode 100644 index 14c9731..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CloseDurableClientCommand.java +++ /dev/null @@ -1,77 +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 java.util.List; -import java.util.Set; - -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; - -import org.apache.geode.cache.execute.ResultCollector; -import org.apache.geode.distributed.DistributedMember; -import org.apache.geode.management.cli.CliMetaData; -import org.apache.geode.management.cli.ConverterHint; -import org.apache.geode.management.cli.Result; -import org.apache.geode.management.internal.cli.CliUtil; -import org.apache.geode.management.internal.cli.domain.MemberResult; -import org.apache.geode.management.internal.cli.functions.CloseDurableClientFunction; -import org.apache.geode.management.internal.cli.i18n.CliStrings; -import org.apache.geode.management.internal.cli.result.ResultBuilder; -import org.apache.geode.management.internal.security.ResourceOperation; -import org.apache.geode.security.ResourcePermission; - -public class CloseDurableClientCommand implements GfshCommand { - DurableClientCommandsResultBuilder builder = new DurableClientCommandsResultBuilder(); - - @CliCommand(value = CliStrings.CLOSE_DURABLE_CLIENTS, - help = CliStrings.CLOSE_DURABLE_CLIENTS__HELP) - @CliMetaData() - @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, - operation = ResourcePermission.Operation.MANAGE, target = ResourcePermission.Target.QUERY) - public Result closeDurableClient( - @CliOption(key = CliStrings.CLOSE_DURABLE_CLIENTS__CLIENT__ID, mandatory = true, - help = CliStrings.CLOSE_DURABLE_CLIENTS__CLIENT__ID__HELP) final String durableClientId, - @CliOption(key = {CliStrings.MEMBER, CliStrings.MEMBERS}, - help = CliStrings.CLOSE_DURABLE_CLIENTS__MEMBER__HELP, - optionContext = ConverterHint.MEMBERIDNAME) final String[] memberNameOrId, - @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS}, - help = CliStrings.COUNT_DURABLE_CQ_EVENTS__GROUP__HELP, - optionContext = ConverterHint.MEMBERGROUP) final String[] group) { - - Result result; - try { - - Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrId); - - if (targetMembers.isEmpty()) { - return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE); - } - - final ResultCollector<?, ?> rc = - CliUtil.executeFunction(new CloseDurableClientFunction(), durableClientId, targetMembers); - final List<MemberResult> results = (List<MemberResult>) rc.getResult(); - String failureHeader = - CliStrings.format(CliStrings.CLOSE_DURABLE_CLIENTS__FAILURE__HEADER, durableClientId); - String successHeader = - CliStrings.format(CliStrings.CLOSE_DURABLE_CLIENTS__SUCCESS, durableClientId); - result = builder.buildResult(results, successHeader, failureHeader); - } catch (Exception e) { - result = ResultBuilder.createGemFireErrorResult(e.getMessage()); - } - return result; - } -}