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/02/07 19:03:30 UTC
[09/19] geode git commit: GEODE-2369: Remove --dir option from export
cluster-config
GEODE-2369: Remove --dir option from export cluster-config
This closes #374
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/9a774862
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/9a774862
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/9a774862
Branch: refs/heads/feature/GEODE-2267
Commit: 9a774862007722e0f57b94b7dd9c4d76cb56db6e
Parents: 4e8bc15
Author: Jared Stewart <js...@pivotal.io>
Authored: Tue Jan 31 09:02:35 2017 -0800
Committer: Kirk Lund <kl...@apache.org>
Committed: Mon Feb 6 15:12:47 2017 -0800
----------------------------------------------------------------------
...xportImportClusterConfigurationCommands.java | 48 +++++++-------------
.../internal/cli/i18n/CliStrings.java | 7 +--
.../internal/cli/result/AbstractResultData.java | 17 +++----
.../controllers/ConfigCommandsController.java | 10 +---
.../ClusterConfigImportDUnitTest.java | 22 ++++++---
.../dunit/rules/GfshShellConnectionRule.java | 2 +-
.../cli/commands/golden-help-offline.properties | 7 +--
7 files changed, 47 insertions(+), 66 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/9a774862/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java
index 5e45f3b..1ee22db 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java
@@ -52,6 +52,8 @@ import org.springframework.shell.core.annotation.CliOption;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -63,6 +65,7 @@ import java.util.Set;
*/
@SuppressWarnings("unused")
public class ExportImportClusterConfigurationCommands extends AbstractCommandsSupport {
+
@CliCommand(value = {CliStrings.EXPORT_SHARED_CONFIG},
help = CliStrings.EXPORT_SHARED_CONFIG__HELP)
@CliMetaData(
@@ -70,25 +73,32 @@ public class ExportImportClusterConfigurationCommands extends AbstractCommandsSu
relatedTopic = {CliStrings.TOPIC_GEODE_CONFIG})
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result exportSharedConfig(@CliOption(key = {CliStrings.EXPORT_SHARED_CONFIG__FILE},
- mandatory = true, help = CliStrings.EXPORT_SHARED_CONFIG__FILE__HELP) String zipFileName,
-
- @CliOption(key = {CliStrings.EXPORT_SHARED_CONFIG__DIR},
- help = CliStrings.EXPORT_SHARED_CONFIG__DIR__HELP) String dir) {
+ mandatory = true, help = CliStrings.EXPORT_SHARED_CONFIG__FILE__HELP) String zipFileName) {
InternalLocator locator = InternalLocator.getLocator();
if (!locator.isSharedConfigurationRunning()) {
return ResultBuilder.createGemFireErrorResult(CliStrings.SHARED_CONFIGURATION_NOT_STARTED);
}
+ Path tempDir;
+ try {
+ tempDir = Files.createTempDirectory("clusterConfig");
+ } catch (IOException e) {
+ logSevere(e);
+ ErrorResultData errorData =
+ ResultBuilder.createErrorResultData().addLine("Unable to create temp directory");
+ return ResultBuilder.buildResult(errorData);
+ }
+
+ File zipFile = tempDir.resolve("exportedCC.zip").toFile();
ClusterConfigurationService sc = locator.getSharedConfiguration();
- File zipFile = new File(zipFileName);
- zipFile.getParentFile().mkdirs();
Result result;
try {
for (Configuration config : sc.getEntireConfiguration().values()) {
sc.writeConfigToFile(config);
}
+
ZipUtils.zip(sc.getSharedConfigurationDirPath(), zipFile.getCanonicalPath());
InfoResultData infoData = ResultBuilder.createInfoResultData();
@@ -240,31 +250,7 @@ public class ExportImportClusterConfigurationCommands extends AbstractCommandsSu
public Result postExecution(GfshParseResult parseResult, Result commandResult) {
if (commandResult.hasIncomingFiles()) {
try {
- Map<String, String> paramValueMap = parseResult.getParamValueStrings();
- String dir = paramValueMap.get(CliStrings.EXPORT_SHARED_CONFIG__DIR);
- dir = (dir == null) ? null : dir.trim();
-
- File saveDirFile = new File(".");
-
- if (dir != null && !dir.isEmpty()) {
- saveDirFile = new File(dir);
- if (saveDirFile.exists()) {
- if (!saveDirFile.isDirectory()) {
- return ResultBuilder.createGemFireErrorResult(
- CliStrings.format(CliStrings.EXPORT_SHARED_CONFIG__MSG__NOT_A_DIRECTORY, dir));
- }
- } else if (!saveDirFile.mkdirs()) {
- return ResultBuilder.createGemFireErrorResult(
- CliStrings.format(CliStrings.EXPORT_SHARED_CONFIG__MSG__CANNOT_CREATE_DIR, dir));
- }
- }
- if (!saveDirFile.canWrite()) {
- return ResultBuilder.createGemFireErrorResult(
- CliStrings.format(CliStrings.EXPORT_SHARED_CONFIG__MSG__NOT_WRITEABLE,
- saveDirFile.getCanonicalPath()));
- }
- saveDirString = saveDirFile.getAbsolutePath();
- commandResult.saveIncomingFiles(saveDirString);
+ commandResult.saveIncomingFiles(System.getProperty("user.dir"));
return commandResult;
} catch (IOException ioex) {
logger.error(ioex);
http://git-wip-us.apache.org/repos/asf/geode/blob/9a774862/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 393b0c4..4c22c44 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
@@ -3049,16 +3049,13 @@ public class CliStrings {
/***
* Cluster Configuration commands
*/
-
+ // TODO: Jared - clean up messages
public static final String EXPORT_SHARED_CONFIG = "export cluster-configuration";
public static final String EXPORT_SHARED_CONFIG__HELP =
"Exports the cluster configuration artifacts as a zip file.";
- public static final String EXPORT_SHARED_CONFIG__DIR = "dir";
- public static final String EXPORT_SHARED_CONFIG__DIR__HELP =
- "The directory in which the exported cluster configuration artifacts will be saved";
public static final String EXPORT_SHARED_CONFIG__FILE = "zip-file-name";
public static final String EXPORT_SHARED_CONFIG__FILE__HELP =
- "Name of the zip file containing the exported cluster configuration artifacts";
+ "Path to the zip file containing the exported cluster configuration artifacts";
public static final String EXPORT_SHARED_CONFIG__MSG__NOT_A_DIRECTORY = "{0} is not a directory.";
public static final String EXPORT_SHARED_CONFIG__MSG__CANNOT_CREATE_DIR =
"Directory {0} could not be created.";
http://git-wip-us.apache.org/repos/asf/geode/blob/9a774862/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/AbstractResultData.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/AbstractResultData.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/AbstractResultData.java
index 96347c8..e08d9b7 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/AbstractResultData.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/result/AbstractResultData.java
@@ -241,28 +241,25 @@ public abstract class AbstractResultData implements ResultData {
}
String fileMessage = new String(fileMessageBytes);
- // System.out.println(object.names());
- // System.out.println(fileName);
-
GfJsonObject fileDataBytes = object.getJSONObject(FILE_DATA_FIELD);
byte[] byteArray = GfJsonArray.toByteArray(fileDataBytes.getJSONArray(DATA_FIELD));
int dataLength = fileDataBytes.getInt(DATA_LENGTH_FIELD);
DeflaterInflaterData uncompressBytes = CliUtil.uncompressBytes(byteArray, dataLength);
byte[] uncompressed = uncompressBytes.getData();
- // String encodedString = object.getString(FILE_DATA_FIELD);
- // byte[] uncompressed = Base64.decode(encodedString, Base64.GZIP);
-
- if (directory == null || directory.isEmpty()) {
- directory = System.getProperty("user.dir", ".");
- }
-
boolean isGfshVM = CliUtil.isGfshVM();
File fileToDumpData = new File(fileName);
if (!fileToDumpData.isAbsolute()) {
+ if (directory == null || directory.isEmpty()) {
+ directory = System.getProperty("user.dir", ".");
+ }
fileToDumpData = new File(directory, fileName);
}
+
File parentDirectory = fileToDumpData.getParentFile();
+ if (parentDirectory != null) {
+ parentDirectory.mkdirs();
+ }
if (fileToDumpData.exists()) {
String fileExistsMessage =
CliStrings.format(CliStrings.ABSTRACTRESULTDATA__MSG__FILE_WITH_NAME_0_EXISTS_IN_1,
http://git-wip-us.apache.org/repos/asf/geode/blob/9a774862/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/ConfigCommandsController.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/ConfigCommandsController.java b/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/ConfigCommandsController.java
index d3d9c4d..f468c65 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/ConfigCommandsController.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/ConfigCommandsController.java
@@ -201,16 +201,10 @@ public class ConfigCommandsController extends AbstractMultiPartCommandsControlle
@RequestMapping(method = RequestMethod.GET, value = "/config/cluster")
public Callable<ResponseEntity<String>> exportClusterConfig(
- @RequestParam(CliStrings.EXPORT_SHARED_CONFIG__FILE) final String zipFileName,
- @RequestParam(value = CliStrings.EXPORT_SHARED_CONFIG__DIR,
- required = false) final String directory) {
+ @RequestParam(CliStrings.EXPORT_SHARED_CONFIG__FILE) final String zipFile) {
final CommandStringBuilder command = new CommandStringBuilder(CliStrings.EXPORT_SHARED_CONFIG);
- command.addOption(CliStrings.EXPORT_SHARED_CONFIG__FILE, zipFileName);
-
- if (hasValue(directory)) {
- command.addOption(CliStrings.EXPORT_SHARED_CONFIG__DIR, directory);
- }
+ command.addOption(CliStrings.EXPORT_SHARED_CONFIG__FILE, zipFile);
return getProcessCommandCallable(command.toString());
}
http://git-wip-us.apache.org/repos/asf/geode/blob/9a774862/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigImportDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigImportDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigImportDUnitTest.java
index 7333c23..d8b4cb3 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigImportDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigImportDUnitTest.java
@@ -173,7 +173,19 @@ public class ClusterConfigImportDUnitTest extends ClusterConfigBaseTest {
}
@Test
- public void testExportClusterConfig() throws Exception {
+ public void testExportWithAbsolutePath() throws Exception {
+ Path exportedZipPath =
+ lsRule.getTempFolder().getRoot().toPath().resolve("exportedCC.zip").toAbsolutePath();
+
+ testExportClusterConfig(exportedZipPath.toString());
+ }
+
+ @Test
+ public void testExportWithRelativePath() throws Exception {
+ testExportClusterConfig("tmp/exportedCC.zip");
+ }
+
+ public void testExportClusterConfig(String zipFilePath) throws Exception {
Server server1 = lsRule.startServerVM(1, serverProps, locator.getPort());
CommandResult result =
@@ -185,20 +197,18 @@ public class ClusterConfigImportDUnitTest extends ClusterConfigBaseTest {
expectedClusterConfig.verify(server1);
expectedClusterConfig.verify(locator);
- Path exportedZipPath = lsRule.getTempFolder().getRoot().toPath().resolve("exportedCC.zip");
- result = gfshConnector
- .executeCommand("export cluster-configuration --zip-file-name=" + exportedZipPath);
+ result =
+ gfshConnector.executeCommand("export cluster-configuration --zip-file-name=" + zipFilePath);
System.out.println(result.getContent());
assertThat(result.getStatus()).isEqualTo(Result.Status.OK);
- File exportedZip = exportedZipPath.toFile();
+ File exportedZip = new File(zipFilePath);
assertThat(exportedZip).exists();
Set<String> actualZipEnries =
new ZipFile(exportedZip).stream().map(ZipEntry::getName).collect(Collectors.toSet());
-
ConfigGroup exportedClusterGroup = cluster.configFiles("cluster.xml", "cluster.properties");
ClusterConfig expectedExportedClusterConfig = new ClusterConfig(exportedClusterGroup);
http://git-wip-us.apache.org/repos/asf/geode/blob/9a774862/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java
index 05f81c8..49c1414 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java
@@ -131,7 +131,7 @@ public class GfshShellConnectionRule extends DescribedExternalResource {
public CommandResult executeCommand(String command) throws Exception {
gfsh.executeCommand(command);
CommandResult result = (CommandResult) gfsh.getResult();
- System.out.println("command result: " + result.getContent().toString());
+ System.out.println("command result: " + result.getContent());
return result;
}
http://git-wip-us.apache.org/repos/asf/geode/blob/9a774862/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties
----------------------------------------------------------------------
diff --git a/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties b/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties
index 91d545f..d0f41e4 100644
--- a/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties
+++ b/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties
@@ -1413,14 +1413,11 @@ IS AVAILABLE\n\
SYNOPSIS\n\
\ \ \ \ Exports the cluster configuration artifacts as a zip file.\n\
SYNTAX\n\
-\ \ \ \ export cluster-configuration --zip-file-name=value [--dir=value]\n\
+\ \ \ \ export cluster-configuration --zip-file-name=value\n\
PARAMETERS\n\
\ \ \ \ zip-file-name\n\
-\ \ \ \ \ \ \ \ Name of the zip file containing the exported cluster configuration artifacts\n\
+\ \ \ \ \ \ \ \ Path to the zip file containing the exported cluster configuration artifacts\n\
\ \ \ \ \ \ \ \ Required: true\n\
-\ \ \ \ dir\n\
-\ \ \ \ \ \ \ \ The directory in which the exported cluster configuration artifacts will be saved\n\
-\ \ \ \ \ \ \ \ Required: false\n\
export-config.help=\
NAME\n\