Repository: geode Updated Branches: refs/heads/develop 8555f6fd4 -> aebd11f0b
GEODE-2837: Start server creates specified working dir if necessary Project: http://git-wip-us.apache.org/repos/asf/geode/repo Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/6d24eaaa Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/6d24eaaa Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/6d24eaaa Branch: refs/heads/develop Commit: 6d24eaaa3db82eebcbb9e91121729fdbdefd3836 Parents: 8555f6f Author: Jared Stewart <[email protected]> Authored: Fri Apr 28 11:20:26 2017 -0700 Committer: Jared Stewart <[email protected]> Committed: Wed May 3 15:36:45 2017 -0700 ---------------------------------------------------------------------- ...auncherLifecycleCommandsIntegrationTest.java | 30 +++++++++++++- .../cli/commands/LauncherLifecycleCommands.java | 42 +++++++++----------- .../internal/cli/i18n/CliStrings.java | 5 +-- 3 files changed, 48 insertions(+), 29 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/geode/blob/6d24eaaa/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommandsIntegrationTest.java ---------------------------------------------------------------------- diff --git a/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommandsIntegrationTest.java b/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommandsIntegrationTest.java index b51505a..29e86e0 100644 --- a/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommandsIntegrationTest.java +++ b/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommandsIntegrationTest.java @@ -14,7 +14,11 @@ */ package org.apache.geode.management.internal.cli.commands; -import static org.junit.Assert.*; + +import static org.assertj.core.api.Java6Assertions.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.io.File; import java.io.FileWriter; @@ -28,6 +32,7 @@ import java.util.jar.Attributes.Name; import java.util.jar.JarFile; import java.util.jar.Manifest; +import org.apache.commons.io.FileUtils; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -168,4 +173,27 @@ public class LauncherLifecycleCommandsIntegrationTest { missingExpectedJarDependenciesList.isEmpty()); } + @Test + public void workingDirDefaultsToMemberName() { + LauncherLifecycleCommands launcherLifecycleCommands = new LauncherLifecycleCommands(); + + String workingDir = launcherLifecycleCommands.resolveWorkingDir(null, "server1"); + assertThat(new File(workingDir)).exists(); + assertThat(workingDir).endsWith("server1"); + } + + + @Test + public void workingDirGetsCreatedIfNecessary() throws Exception { + File workingDir = temporaryFolder.newFolder("foo"); + FileUtils.deleteQuietly(workingDir); + String workingDirString = workingDir.getAbsolutePath(); + + LauncherLifecycleCommands launcherLifecycleCommands = new LauncherLifecycleCommands(); + + String resolvedWorkingDir = + launcherLifecycleCommands.resolveWorkingDir(workingDirString, "server1"); + assertThat(new File(resolvedWorkingDir)).exists(); + assertThat(workingDirString).endsWith("foo"); + } } http://git-wip-us.apache.org/repos/asf/geode/blob/6d24eaaa/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommands.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommands.java index 0e681d7..b3de975 100755 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommands.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommands.java @@ -267,18 +267,7 @@ public class LauncherLifecycleCommands extends AbstractCommandsSupport { memberName = nameGenerator.generate('-'); } - if (workingDirectory == null) { - // attempt to use or make sub-directory using memberName... - File locatorWorkingDirectory = new File(memberName); - - if (!(locatorWorkingDirectory.exists() || locatorWorkingDirectory.mkdir())) { - throw new IllegalStateException(CliStrings.format( - CliStrings.START_LOCATOR__MSG__COULD_NOT_CREATE_DIRECTORY_0_VERIFY_PERMISSIONS, - locatorWorkingDirectory.getAbsolutePath())); - } - - workingDirectory = IOUtils.tryGetCanonicalPathElseGetAbsolutePath(locatorWorkingDirectory); - } + workingDirectory = resolveWorkingDir(workingDirectory, memberName); gemfirePropertiesPathname = CliUtil.resolvePathname(gemfirePropertiesPathname); @@ -1474,18 +1463,7 @@ public class LauncherLifecycleCommands extends AbstractCommandsSupport { } } - if (workingDirectory == null) { - // attempt to use or make sub-directory using memberName... - File serverWorkingDirectory = new File(memberName); - - if (!(serverWorkingDirectory.exists() || serverWorkingDirectory.mkdir())) { - throw new IllegalStateException(CliStrings.format( - CliStrings.START_SERVER__MSG__COULD_NOT_CREATE_DIRECTORY_0_VERIFY_PERMISSIONS, - serverWorkingDirectory.getAbsolutePath())); - } - - workingDirectory = IOUtils.tryGetCanonicalPathElseGetAbsolutePath(serverWorkingDirectory); - } + workingDirectory = resolveWorkingDir(workingDirectory, memberName); cacheXmlPathname = CliUtil.resolvePathname(cacheXmlPathname); @@ -2673,4 +2651,20 @@ public class LauncherLifecycleCommands extends AbstractCommandsSupport { } } + protected String resolveWorkingDir(String userSpecifiedDir, String memberName) { + File workingDir = + (userSpecifiedDir == null) ? new File(memberName) : new File(userSpecifiedDir); + + String workingDirPath = IOUtils.tryGetCanonicalPathElseGetAbsolutePath(workingDir); + + if (!workingDir.exists()) { + if (!workingDir.mkdirs()) { + throw new IllegalStateException(String.format( + "Could not create directory %s. Please verify directory path or user permissions.", + workingDirPath)); + } + } + + return workingDirPath; + } } http://git-wip-us.apache.org/repos/asf/geode/blob/6d24eaaa/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 a793235..25398a1 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 @@ -2412,8 +2412,6 @@ public class CliStrings { public static final String START_LOCATOR__PROCESS_TERMINATED_ABNORMALLY_ERROR_MESSAGE = "The Locator process terminated unexpectedly with exit status %1$d. Please refer to the log file in %2$s for full details.%n%n%3$s"; public static final String START_LOCATOR__RUN_MESSAGE = "Starting a Geode Locator in %1$s..."; - public static final String START_LOCATOR__MSG__COULD_NOT_CREATE_DIRECTORY_0_VERIFY_PERMISSIONS = - "Could not create directory {0}. Please verify directory path or user permissions."; public static final String START_LOCATOR__CONNECT = "connect"; public static final String START_LOCATOR__CONNECT__HELP = "When connect is set to false , Gfsh does not automatically connect to the locator which is started using this command."; @@ -2605,8 +2603,7 @@ public class CliStrings { public static final String START_SERVER__PROCESS_TERMINATED_ABNORMALLY_ERROR_MESSAGE = "The Cache Server process terminated unexpectedly with exit status %1$d. Please refer to the log file in %2$s for full details.%n%n%3$s"; public static final String START_SERVER__RUN_MESSAGE = "Starting a Geode Server in %1$s..."; - public static final String START_SERVER__MSG__COULD_NOT_CREATE_DIRECTORY_0_VERIFY_PERMISSIONS = - "Could not create directory {0}. Please verify directory path or user permissions."; + public static final String START_SERVER__CRITICAL__HEAP__PERCENTAGE = "critical-heap-percentage"; public static final String START_SERVER__CRITICAL__HEAP__HELP =
