geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zho...@apache.org
Subject [40/51] [abbrv] geode git commit: GEODE-2818: add aliases to the undeploy command
Date Wed, 14 Jun 2017 22:07:27 GMT
GEODE-2818: add aliases to the undeploy command

* this closes #560


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/a6433273
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/a6433273
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/a6433273

Branch: refs/heads/feature/GEM-1483
Commit: a6433273251528d2cda3b5f1e6dc4dad4360275f
Parents: db8e1df
Author: Jinmei Liao <jiliao@pivotal.io>
Authored: Wed Jun 7 16:10:56 2017 -0700
Committer: Jinmei Liao <jiliao@pivotal.io>
Committed: Wed Jun 14 08:59:51 2017 -0700

----------------------------------------------------------------------
 .../internal/cli/commands/ConfigCommands.java   |  7 +--
 .../internal/cli/commands/DeployCommands.java   | 50 +++++++++++---------
 .../internal/cli/functions/DeployFunction.java  |  3 --
 .../cli/functions/UndeployFunction.java         |  9 ++--
 .../cli/GfshParserAutoCompletionTest.java       |  6 +--
 .../cli/commands/DeployCommandsDUnitTest.java   | 36 +++++++++++++-
 6 files changed, 74 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/a6433273/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ConfigCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ConfigCommands.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ConfigCommands.java
index 19c72c3..a8afa7d 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ConfigCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ConfigCommands.java
@@ -81,9 +81,10 @@ public class ConfigCommands implements GfshCommand {
   @ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
   public Result describeConfig(
       @CliOption(key = CliStrings.MEMBER, optionContext = ConverterHint.ALL_MEMBER_IDNAME,
-          help = CliStrings.DESCRIBE_CONFIG__MEMBER__HELP, mandatory = true)
-
-      String memberNameOrId, @CliOption(key = CliStrings.DESCRIBE_CONFIG__HIDE__DEFAULTS,
help = CliStrings.DESCRIBE_CONFIG__HIDE__DEFAULTS__HELP, unspecifiedDefaultValue = "true",
specifiedDefaultValue = "true") boolean hideDefaults) {
+          help = CliStrings.DESCRIBE_CONFIG__MEMBER__HELP, mandatory = true) String memberNameOrId,
+      @CliOption(key = CliStrings.DESCRIBE_CONFIG__HIDE__DEFAULTS,
+          help = CliStrings.DESCRIBE_CONFIG__HIDE__DEFAULTS__HELP, unspecifiedDefaultValue
= "true",
+          specifiedDefaultValue = "true") boolean hideDefaults) {
 
     Result result = null;
     try {

http://git-wip-us.apache.org/repos/asf/geode/blob/a6433273/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommands.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommands.java
index 43a748e..9b79e1d 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommands.java
@@ -15,6 +15,8 @@
 package org.apache.geode.management.internal.cli.commands;
 
 import static org.apache.commons.io.FileUtils.ONE_MB;
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.lang.StringUtils;
 
 import org.apache.geode.SystemFailure;
 import org.apache.geode.cache.execute.ResultCollector;
@@ -66,7 +68,7 @@ public class DeployCommands implements GfshCommand {
    * Deploy one or more JAR files to members of a group or all members.
    * 
    * @param groups Group(s) to deploy the JAR to or null for all members
-   * @param jar JAR file to deploy
+   * @param jars JAR file to deploy
    * @param dir Directory of JAR files to deploy
    * @return The result of the attempt to deploy
    */
@@ -77,7 +79,8 @@ public class DeployCommands implements GfshCommand {
   public Result deploy(
       @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS}, help = CliStrings.DEPLOY__GROUP__HELP,
           optionContext = ConverterHint.MEMBERGROUP) String[] groups,
-      @CliOption(key = {CliStrings.JAR}, help = CliStrings.DEPLOY__JAR__HELP) String jar,
+      @CliOption(key = {CliStrings.JAR, CliStrings.JARS},
+          help = CliStrings.DEPLOY__JAR__HELP) String[] jars,
       @CliOption(key = {CliStrings.DEPLOY__DIR}, help = CliStrings.DEPLOY__DIR__HELP) String
dir) {
     try {
 
@@ -157,8 +160,8 @@ public class DeployCommands implements GfshCommand {
       @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS},
           help = CliStrings.UNDEPLOY__GROUP__HELP,
           optionContext = ConverterHint.MEMBERGROUP) String[] groups,
-      @CliOption(key = {CliStrings.JAR}, help = CliStrings.UNDEPLOY__JAR__HELP,
-          unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE) String jars) {
+      @CliOption(key = {CliStrings.JAR, CliStrings.JARS}, help = CliStrings.UNDEPLOY__JAR__HELP,
+          unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE) String[] jars) {
 
     try {
       TabularResultData tabularData = ResultBuilder.createTabularResultData();
@@ -175,6 +178,7 @@ public class DeployCommands implements GfshCommand {
       List<CliFunctionResult> results = CliFunctionResult.cleanResults((List<?>)
rc.getResult());
 
       for (CliFunctionResult result : results) {
+
         if (result.getThrowable() != null) {
           tabularData.accumulate("Member", result.getMemberIdOrName());
           tabularData.accumulate("Un-Deployed JAR", "");
@@ -200,8 +204,8 @@ public class DeployCommands implements GfshCommand {
 
       Result result = ResultBuilder.buildResult(tabularData);
       if (tabularData.getStatus().equals(Status.OK)) {
-        persistClusterConfiguration(result, () -> getSharedConfiguration()
-            .removeJars(jars == null ? null : jars.split(","), groups));
+        persistClusterConfiguration(result,
+            () -> getSharedConfiguration().removeJars(jars, groups));
       }
       return result;
     } catch (VirtualMachineError e) {
@@ -283,29 +287,31 @@ public class DeployCommands implements GfshCommand {
 
     @Override
     public Result preExecution(GfshParseResult parseResult) {
-      Map<String, String> paramValueMap = parseResult.getParamValueStrings();
-
-      String jar = paramValueMap.get("jar");
-      jar = jar == null ? null : jar.trim();
-
-      String dir = paramValueMap.get("dir");
-      dir = dir == null ? null : dir.trim();
-
-      String group = paramValueMap.get("group");
-      group = group == null ? null : group.trim();
-
-      String jarOrDir = jar != null ? jar : dir;
+      // 2nd argument is the jar
+      String[] jars = (String[]) parseResult.getArguments()[1];
+      // 3rd arguemnt is the dir
+      String dir = (String) parseResult.getArguments()[2];
 
-      if (jar == null && dir == null) {
+      if (ArrayUtils.isEmpty(jars) && StringUtils.isBlank(dir)) {
         return ResultBuilder.createUserErrorResult(
             "Parameter \"jar\" or \"dir\" is required. Use \"help <command name>\"
for assistance.");
       }
 
+      if (ArrayUtils.isNotEmpty(jars) && StringUtils.isNotBlank(dir)) {
+        return ResultBuilder
+            .createUserErrorResult("Parameters \"jar\" and \"dir\" can not both be specified.");
+      }
+
       FileResult fileResult;
+      String[] filesToUpload = jars;
+      if (filesToUpload == null) {
+        filesToUpload = new String[] {dir};
+      }
       try {
-        fileResult = new FileResult(new String[] {jar != null ? jar : dir});
+
+        fileResult = new FileResult(filesToUpload);
       } catch (FileNotFoundException fnfex) {
-        return ResultBuilder.createGemFireErrorResult("'" + jarOrDir + "' not found.");
+        return ResultBuilder.createGemFireErrorResult("'" + filesToUpload + "' not found.");
       } catch (IOException ioex) {
         return ResultBuilder.createGemFireErrorResult("I/O error when reading jar/dir: "
             + ioex.getClass().getName() + ": " + ioex.getMessage());
@@ -320,7 +326,7 @@ public class DeployCommands implements GfshCommand {
 
         if (readYesNo(message, Response.YES) == Response.NO) {
           return ResultBuilder
-              .createShellClientAbortOperationResult("Aborted deploy of " + jarOrDir + ".");
+              .createShellClientAbortOperationResult("Aborted deploy of " + filesToUpload
+ ".");
         }
       }
 

http://git-wip-us.apache.org/repos/asf/geode/blob/a6433273/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DeployFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DeployFunction.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DeployFunction.java
index f1b1cd6..401a368 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DeployFunction.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DeployFunction.java
@@ -54,9 +54,6 @@ public class DeployFunction implements Function, InternalEntity {
       final byte[][] jarBytes = (byte[][]) args[1];
       InternalCache cache = getCache();
 
-      final JarDeployer jarDeployer =
-          new JarDeployer(cache.getInternalDistributedSystem().getConfig().getDeployWorkingDir());
-
       DistributedMember member = cache.getDistributedSystem().getDistributedMember();
 
       memberId = member.getId();

http://git-wip-us.apache.org/repos/asf/geode/blob/a6433273/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/UndeployFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/UndeployFunction.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/UndeployFunction.java
index 64ed367..031c855 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/UndeployFunction.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/UndeployFunction.java
@@ -18,6 +18,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.StringTokenizer;
 
+import org.apache.commons.lang.ArrayUtils;
 import org.apache.geode.internal.ClassPathLoader;
 import org.apache.logging.log4j.Logger;
 
@@ -51,7 +52,7 @@ public class UndeployFunction implements Function, InternalEntity {
 
     try {
       final Object[] args = (Object[]) context.getArguments();
-      final String jarFilenameList = (String) args[0]; // Comma separated
+      final String[] jarFilenameList = (String[]) args[0]; // Comma separated
       InternalCache cache = getCache();
 
       final JarDeployer jarDeployer = ClassPathLoader.getLatest().getJarDeployer();
@@ -65,7 +66,7 @@ public class UndeployFunction implements Function, InternalEntity {
       }
 
       String[] undeployedJars = new String[0];
-      if (jarFilenameList == null || jarFilenameList.equals("")) {
+      if (ArrayUtils.isEmpty(jarFilenameList)) {
         final List<DeployedJar> jarClassLoaders = jarDeployer.findDeployedJars();
         undeployedJars = new String[jarClassLoaders.size() * 2];
         int index = 0;
@@ -81,9 +82,7 @@ public class UndeployFunction implements Function, InternalEntity {
         }
       } else {
         List<String> undeployedList = new ArrayList<String>();
-        StringTokenizer jarTokenizer = new StringTokenizer(jarFilenameList, ",");
-        while (jarTokenizer.hasMoreTokens()) {
-          String jarFilename = jarTokenizer.nextToken().trim();
+        for (String jarFilename : jarFilenameList) {
           try {
             undeployedList.add(jarFilename);
             undeployedList.add(ClassPathLoader.getLatest().getJarDeployer().undeploy(jarFilename));

http://git-wip-us.apache.org/repos/asf/geode/blob/a6433273/geode-core/src/test/java/org/apache/geode/management/internal/cli/GfshParserAutoCompletionTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/GfshParserAutoCompletionTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/GfshParserAutoCompletionTest.java
index a2946d4..4069c06 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/GfshParserAutoCompletionTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/GfshParserAutoCompletionTest.java
@@ -53,7 +53,7 @@ public class GfshParserAutoCompletionTest {
   public void testCompletionDeploy() throws Exception {
     buffer = "deploy";
     candidate = parser.complete(buffer);
-    assertThat(candidate.size()).isEqualTo(3);
+    assertThat(candidate.size()).isEqualTo(5);
     assertThat(candidate.getFirstCandidate()).isEqualTo(buffer + " --dir");
   }
 
@@ -61,7 +61,7 @@ public class GfshParserAutoCompletionTest {
   public void testCompletionDeployWithSpace() throws Exception {
     buffer = "deploy ";
     candidate = parser.complete(buffer);
-    assertThat(candidate.size()).isEqualTo(3);
+    assertThat(candidate.size()).isEqualTo(5);
     assertThat(candidate.getFirstCandidate()).isEqualTo(buffer + "--dir");
   }
 
@@ -244,7 +244,7 @@ public class GfshParserAutoCompletionTest {
   public void testCompletWithRegionTypeWithSpace() throws Exception {
     buffer = "create region --name=test --type=REPLICATE ";
     candidate = parser.complete(buffer);
-    assertThat(candidate.size()).isEqualTo(37);
+    assertThat(candidate.size()).isEqualTo(38);
     assertThat(candidate.getFirstCandidate()).isEqualTo(buffer + "--async-event-queue-id");
   }
 

http://git-wip-us.apache.org/repos/asf/geode/blob/a6433273/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandsDUnitTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandsDUnitTest.java
index 3a88faa..846a8d9 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandsDUnitTest.java
@@ -120,7 +120,7 @@ public class DeployCommandsDUnitTest implements Serializable {
   }
 
   @Test
-  public void deployMultipleJarsToOneGroup() throws Exception {
+  public void deployJarsInDirToOneGroup() throws Exception {
     // Deploy of multiple JARs to a single group
     gfshConnector.executeAndVerifyCommand(
         "deploy --group=" + GROUP1 + " --dir=" + subdirWithJars3and4.getCanonicalPath());
@@ -153,6 +153,40 @@ public class DeployCommandsDUnitTest implements Serializable {
   }
 
   @Test
+  public void deployMultipleJarsToOneGroup() throws Exception {
+    // Deploy of multiple JARs to a single group
+    gfshConnector.executeAndVerifyCommand("deploy --group=" + GROUP1 + " --jars="
+        + jar3.getAbsolutePath() + "," + jar4.getAbsolutePath());
+    String resultString = gfshConnector.getGfshOutput();
+
+    assertThat(resultString).describedAs(resultString).contains(server1.getName());
+    assertThat(resultString).doesNotContain(server2.getName());
+    assertThat(resultString).contains(jarName3);
+    assertThat(resultString).contains(jarName4);
+
+    server1.invoke(() -> {
+      assertThatCanLoad(jarName3, class3);
+      assertThatCanLoad(jarName4, class4);
+    });
+    server2.invoke(() -> {
+      assertThatCannotLoad(jarName3, class3);
+      assertThatCannotLoad(jarName4, class4);
+    });
+
+    // Undeploy of multiple jars by specifying group
+    gfshConnector.executeAndVerifyCommand("undeploy --jars=" + jarName3 + "," + jarName4);
+    server1.invoke(() -> {
+      assertThatCannotLoad(jarName3, class3);
+      assertThatCannotLoad(jarName4, class4);
+    });
+    server2.invoke(() -> {
+      assertThatCannotLoad(jarName3, class3);
+      assertThatCannotLoad(jarName4, class4);
+    });
+  }
+
+
+  @Test
   public void deployJarToAllServers() throws Exception {
     // Deploy a jar to all servers
     gfshConnector.executeAndVerifyCommand("deploy --jar=" + jar1);


Mime
View raw message