This is an automated email from the ASF dual-hosted git repository.
jensdeppe pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push:
new 61a25da GEODE-5971: Refactoring various commands (#3294)
61a25da is described below
commit 61a25da28b1e57a4d044f465dc798087fe65ff91
Author: Jens Deppe <[email protected]>
AuthorDate: Wed Mar 13 05:07:31 2019 -0700
GEODE-5971: Refactoring various commands (#3294)
* GEODE-5971: Refactoring various commands
- DeployCommand
- DestroyFunctionCommand
- ExecuteFunctionCommand
- ListDeployedCommand
- ListFunctionCommand
- UndeployCommand
Co-authored-by: Jens Deppe <[email protected]>
Co-authored-by: Jinmei Liao <[email protected]>
---
.../cli/commands/DeployWithGroupsDUnitTest.java | 10 ++-
.../internal/cli/commands/DeployCommand.java | 3 +-
.../cli/commands/DestroyFunctionCommand.java | 3 +-
.../cli/commands/ExecuteFunctionCommand.java | 3 +-
.../internal/cli/commands/ListDeployedCommand.java | 74 ++++++------------
.../internal/cli/commands/ListFunctionCommand.java | 64 +++++----------
.../internal/cli/commands/UndeployCommand.java | 91 ++++++++++------------
.../cli/functions/ListDeployedFunction.java | 27 ++-----
.../cli/functions/ListFunctionFunction.java | 29 +++----
.../internal/cli/functions/UndeployFunction.java | 67 +++++++---------
.../commands/FunctionCommandsDUnitTestBase.java | 87 ++++++++++++++-------
11 files changed, 205 insertions(+), 253 deletions(-)
diff --git
a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/DeployWithGroupsDUnitTest.java
b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/DeployWithGroupsDUnitTest.java
index abdff44..3b9db5e 100644
---
a/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/DeployWithGroupsDUnitTest.java
+++
b/geode-core/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/DeployWithGroupsDUnitTest.java
@@ -164,9 +164,15 @@ public class DeployWithGroupsDUnitTest implements
Serializable {
assertThatCannotLoad(jarName4, class4);
});
- // Undeploy of multiple jars by specifying group
+ // Undeploy of multiple jars without specifying group
gfshConnector.executeAndAssertThat("undeploy --jars=" + jarName3 + "," +
jarName4)
- .statusIsSuccess();
+ .statusIsSuccess()
+ .hasTableSection("jars")
+ .hasRowSize(4)
+ .hasRowContaining("server-1", "DeployCommandsDUnit3.jar")
+ .hasRowContaining("server-1", "DeployCommandsDUnit4.jar")
+ .hasRowContaining("server-2", "DeployCommandsDUnit3.jar", "JAR not
deployed")
+ .hasRowContaining("server-2", "DeployCommandsDUnit4.jar", "JAR not
deployed");
server1.invoke(() -> {
assertThatCannotLoad(jarName3, class3);
assertThatCannotLoad(jarName4, class4);
diff --git
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommand.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommand.java
index 712bd87..f3b0bba 100644
---
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommand.java
+++
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DeployCommand.java
@@ -40,6 +40,7 @@ import
org.apache.geode.distributed.internal.InternalConfigurationPersistenceSer
import org.apache.geode.internal.DeployedJar;
import org.apache.geode.management.cli.CliMetaData;
import org.apache.geode.management.cli.ConverterHint;
+import org.apache.geode.management.cli.GfshCommand;
import org.apache.geode.management.cli.Result;
import org.apache.geode.management.internal.ManagementAgent;
import org.apache.geode.management.internal.SystemManagementService;
@@ -58,7 +59,7 @@ import
org.apache.geode.management.internal.cli.result.model.TabularResultModel;
import org.apache.geode.management.internal.security.ResourceOperation;
import org.apache.geode.security.ResourcePermission;
-public class DeployCommand extends InternalGfshCommand {
+public class DeployCommand extends GfshCommand {
private final DeployFunction deployFunction = new DeployFunction();
/**
diff --git
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DestroyFunctionCommand.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DestroyFunctionCommand.java
index eb7af7e..14882af 100644
---
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DestroyFunctionCommand.java
+++
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DestroyFunctionCommand.java
@@ -31,6 +31,7 @@ import org.apache.geode.cache.execute.FunctionService;
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.GfshCommand;
import org.apache.geode.management.cli.Result;
import org.apache.geode.management.internal.cli.AbstractCliAroundInterceptor;
import org.apache.geode.management.internal.cli.GfshParseResult;
@@ -41,7 +42,7 @@ import
org.apache.geode.management.internal.cli.result.model.ResultModel;
import org.apache.geode.management.internal.security.ResourceOperation;
import org.apache.geode.security.ResourcePermission;
-public class DestroyFunctionCommand extends InternalGfshCommand {
+public class DestroyFunctionCommand extends GfshCommand {
@CliCommand(value = CliStrings.DESTROY_FUNCTION, help =
CliStrings.DESTROY_FUNCTION__HELP)
@CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_FUNCTION},
interceptor =
"org.apache.geode.management.internal.cli.commands.DestroyFunctionCommand$Interceptor")
diff --git
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExecuteFunctionCommand.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExecuteFunctionCommand.java
index 2111c44..cd364b2 100644
---
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExecuteFunctionCommand.java
+++
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExecuteFunctionCommand.java
@@ -29,6 +29,7 @@ import org.springframework.shell.core.annotation.CliOption;
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.GfshCommand;
import org.apache.geode.management.internal.cli.CliAroundInterceptor;
import org.apache.geode.management.internal.cli.GfshParseResult;
import org.apache.geode.management.internal.cli.functions.CliFunctionResult;
@@ -37,7 +38,7 @@ import
org.apache.geode.management.internal.cli.i18n.CliStrings;
import org.apache.geode.management.internal.cli.result.model.ResultModel;
import
org.apache.geode.management.internal.cli.result.model.TabularResultModel;
-public class ExecuteFunctionCommand extends InternalGfshCommand {
+public class ExecuteFunctionCommand extends GfshCommand {
@CliCommand(value = CliStrings.EXECUTE_FUNCTION, help =
CliStrings.EXECUTE_FUNCTION__HELP)
@CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_FUNCTION},
interceptor =
"org.apache.geode.management.internal.cli.commands.ExecuteFunctionCommand$ExecuteFunctionCommandInterceptor")
diff --git
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListDeployedCommand.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListDeployedCommand.java
index c8651dc..0b3efa9 100644
---
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListDeployedCommand.java
+++
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListDeployedCommand.java
@@ -16,26 +16,24 @@
package org.apache.geode.management.internal.cli.commands;
import java.util.List;
+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.SystemFailure;
-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.Result;
-import org.apache.geode.management.internal.cli.CliUtil;
+import org.apache.geode.management.cli.GfshCommand;
import org.apache.geode.management.internal.cli.functions.CliFunctionResult;
import org.apache.geode.management.internal.cli.functions.ListDeployedFunction;
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.cli.result.model.ResultModel;
+import
org.apache.geode.management.internal.cli.result.model.TabularResultModel;
import org.apache.geode.management.internal.security.ResourceOperation;
import org.apache.geode.security.ResourcePermission;
-public class ListDeployedCommand extends InternalGfshCommand {
+public class ListDeployedCommand extends GfshCommand {
private final ListDeployedFunction listDeployedFunction = new
ListDeployedFunction();
/**
@@ -48,55 +46,33 @@ public class ListDeployedCommand extends
InternalGfshCommand {
@CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_CONFIG})
@ResourceOperation(resource = ResourcePermission.Resource.CLUSTER,
operation = ResourcePermission.Operation.READ)
- public Result listDeployed(@CliOption(key = {CliStrings.GROUP,
CliStrings.GROUPS},
+ public ResultModel listDeployed(@CliOption(key = {CliStrings.GROUP,
CliStrings.GROUPS},
help = CliStrings.LIST_DEPLOYED__GROUP__HELP) String[] group) {
- try {
- TabularResultData tabularData = ResultBuilder.createTabularResultData();
- boolean accumulatedData = false;
-
- Set<DistributedMember> targetMembers = findMembers(group, null);
+ Set<DistributedMember> targetMembers = findMembers(group, null);
+ if (targetMembers.isEmpty()) {
+ return ResultModel.createError(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
+ }
- if (targetMembers.isEmpty()) {
- return
ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
- }
+ ResultModel result = new ResultModel();
+ TabularResultModel tabularData = result.addTable("jars");
- ResultCollector<?, ?> rc =
- CliUtil.executeFunction(this.listDeployedFunction, null,
targetMembers);
- List<CliFunctionResult> results =
CliFunctionResult.cleanResults((List<?>) rc.getResult());
+ List<CliFunctionResult> functionResults =
executeAndGetFunctionResult(this.listDeployedFunction,
+ null, targetMembers);
- for (CliFunctionResult result : results) {
- if (result.getThrowable() != null) {
- tabularData.accumulate("Member", result.getMemberIdOrName());
- tabularData.accumulate("JAR", "");
- tabularData.accumulate("JAR Location",
- "ERROR: " + result.getThrowable().getClass().getName() + ": "
- + result.getThrowable().getMessage());
- accumulatedData = true;
- tabularData.setStatus(Result.Status.ERROR);
- } else {
- String[] strings = (String[]) result.getSerializables();
- for (int i = 0; i < strings.length; i += 2) {
- tabularData.accumulate("Member", result.getMemberIdOrName());
- tabularData.accumulate("JAR", strings[i]);
- tabularData.accumulate("JAR Location", strings[i + 1]);
- accumulatedData = true;
- }
- }
+ for (CliFunctionResult cliResult : functionResults) {
+ Map<String, String> strings = (Map<String, String>)
cliResult.getResultObject();
+ for (Map.Entry<String, String> jar : strings.entrySet()) {
+ tabularData.accumulate("Member", cliResult.getMemberIdOrName());
+ tabularData.accumulate("JAR", jar.getKey());
+ tabularData.accumulate("JAR Location", jar.getValue());
}
+ }
- if (!accumulatedData) {
- return
ResultBuilder.createInfoResult(CliStrings.LIST_DEPLOYED__NO_JARS_FOUND_MESSAGE);
- }
- return ResultBuilder.buildResult(tabularData);
-
- } catch (VirtualMachineError e) {
- SystemFailure.initiateFailure(e);
- throw e;
- } catch (Throwable th) {
- SystemFailure.checkFailure();
- return ResultBuilder.createGemFireErrorResult("Exception while
attempting to list deployed: "
- + th.getClass().getName() + ": " + th.getMessage());
+ if (tabularData.getRowSize() == 0) {
+ return
ResultModel.createInfo(CliStrings.LIST_DEPLOYED__NO_JARS_FOUND_MESSAGE);
}
+
+ return result;
}
}
diff --git
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListFunctionCommand.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListFunctionCommand.java
index 7491f0b..af0c813 100644
---
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListFunctionCommand.java
+++
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ListFunctionCommand.java
@@ -22,29 +22,26 @@ import java.util.Set;
import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.shell.core.annotation.CliOption;
-import org.apache.geode.SystemFailure;
-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.cli.GfshCommand;
import org.apache.geode.management.internal.cli.functions.CliFunctionResult;
import org.apache.geode.management.internal.cli.functions.ListFunctionFunction;
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.cli.result.model.ResultModel;
+import
org.apache.geode.management.internal.cli.result.model.TabularResultModel;
import org.apache.geode.management.internal.security.ResourceOperation;
import org.apache.geode.security.ResourcePermission;
-public class ListFunctionCommand extends InternalGfshCommand {
+public class ListFunctionCommand extends GfshCommand {
private final ListFunctionFunction listFunctionFunction = new
ListFunctionFunction();
@CliCommand(value = CliStrings.LIST_FUNCTION, help =
CliStrings.LIST_FUNCTION__HELP)
@CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_FUNCTION})
@ResourceOperation(resource = ResourcePermission.Resource.CLUSTER,
operation = ResourcePermission.Operation.READ)
- public Result listFunction(
+ public ResultModel listFunction(
@CliOption(key = CliStrings.LIST_FUNCTION__MATCHES,
help = CliStrings.LIST_FUNCTION__MATCHES__HELP) String matches,
@CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS},
@@ -53,49 +50,30 @@ public class ListFunctionCommand extends
InternalGfshCommand {
@CliOption(key = {CliStrings.MEMBER, CliStrings.MEMBERS},
optionContext = ConverterHint.MEMBERIDNAME,
help = CliStrings.LIST_FUNCTION__MEMBER__HELP) String[] members) {
- TabularResultData tabularData = ResultBuilder.createTabularResultData();
- boolean accumulatedData = false;
-
Set<DistributedMember> targetMembers = findMembers(groups, members);
if (targetMembers.isEmpty()) {
- return
ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
+ return ResultModel.createError(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
- try {
- ResultCollector<?, ?> rc =
- CliUtil.executeFunction(this.listFunctionFunction, new Object[]
{matches}, targetMembers);
- List<CliFunctionResult> results =
CliFunctionResult.cleanResults((List<?>) rc.getResult());
+ List<CliFunctionResult> results =
executeAndGetFunctionResult(this.listFunctionFunction,
+ new Object[] {matches}, targetMembers);
- for (CliFunctionResult result : results) {
- if (result.getThrowable() != null) {
- tabularData.accumulate("Member", result.getMemberIdOrName());
- tabularData.accumulate("Function", "<ERROR: " +
result.getThrowable().getMessage() + ">");
- accumulatedData = true;
- tabularData.setStatus(Result.Status.ERROR);
- } else if (result.isSuccessful()) {
- String[] strings = (String[]) result.getSerializables();
- Arrays.sort(strings);
- for (String string : strings) {
- tabularData.accumulate("Member", result.getMemberIdOrName());
- tabularData.accumulate("Function", string);
- accumulatedData = true;
- }
- }
+ ResultModel result = new ResultModel();
+ TabularResultModel tabularData = result.addTable("functions");
+ for (CliFunctionResult cliResult : results) {
+ String[] strings = ((Set<String>)
cliResult.getResultObject()).toArray(new String[0]);
+ Arrays.sort(strings);
+ for (String string : strings) {
+ tabularData.accumulate("Member", cliResult.getMemberIdOrName());
+ tabularData.accumulate("Function", string);
}
+ }
- if (!accumulatedData) {
- return ResultBuilder
-
.createInfoResult(CliStrings.LIST_FUNCTION__NO_FUNCTIONS_FOUND_ERROR_MESSAGE);
- }
- return ResultBuilder.buildResult(tabularData);
- } catch (VirtualMachineError e) {
- SystemFailure.initiateFailure(e);
- throw e;
- } catch (Throwable th) {
- SystemFailure.checkFailure();
- return ResultBuilder.createGemFireErrorResult(
- "Exception while attempting to list functions: " + th.getMessage());
+ if (tabularData.getRowSize() == 0) {
+ return
ResultModel.createInfo(CliStrings.LIST_FUNCTION__NO_FUNCTIONS_FOUND_ERROR_MESSAGE);
}
+ return result;
+
}
}
diff --git
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/UndeployCommand.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/UndeployCommand.java
index 65f4fdf..720de54 100644
---
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/UndeployCommand.java
+++
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/UndeployCommand.java
@@ -16,28 +16,28 @@
package org.apache.geode.management.internal.cli.commands;
import java.util.List;
+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.SystemFailure;
-import org.apache.geode.cache.execute.ResultCollector;
import org.apache.geode.distributed.DistributedMember;
import
org.apache.geode.distributed.internal.InternalConfigurationPersistenceService;
import org.apache.geode.management.cli.CliMetaData;
import org.apache.geode.management.cli.ConverterHint;
+import org.apache.geode.management.cli.GfshCommand;
import org.apache.geode.management.cli.Result;
-import org.apache.geode.management.internal.cli.CliUtil;
import org.apache.geode.management.internal.cli.functions.CliFunctionResult;
import org.apache.geode.management.internal.cli.functions.UndeployFunction;
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.cli.remote.CommandExecutor;
+import org.apache.geode.management.internal.cli.result.model.ResultModel;
+import
org.apache.geode.management.internal.cli.result.model.TabularResultModel;
import org.apache.geode.management.internal.security.ResourceOperation;
import org.apache.geode.security.ResourcePermission;
-public class UndeployCommand extends InternalGfshCommand {
+public class UndeployCommand extends GfshCommand {
private final UndeployFunction undeployFunction = new UndeployFunction();
/**
@@ -51,66 +51,55 @@ public class UndeployCommand extends InternalGfshCommand {
@CliMetaData(relatedTopic = {CliStrings.TOPIC_GEODE_CONFIG})
@ResourceOperation(resource = ResourcePermission.Resource.CLUSTER,
operation = ResourcePermission.Operation.MANAGE, target =
ResourcePermission.Target.DEPLOY)
- public Result undeploy(
+ public ResultModel undeploy(
@CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS},
help = CliStrings.UNDEPLOY__GROUP__HELP,
optionContext = ConverterHint.MEMBERGROUP) String[] groups,
@CliOption(key = {CliStrings.JAR, CliStrings.JARS},
help = CliStrings.UNDEPLOY__JAR__HELP) String[] jars) {
- try {
- TabularResultData tabularData = ResultBuilder.createTabularResultData();
- boolean accumulatedData = false;
+ Set<DistributedMember> targetMembers = findMembers(groups, null);
- Set<DistributedMember> targetMembers = findMembers(groups, null);
-
- if (targetMembers.isEmpty()) {
- return
ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
- }
-
- ResultCollector<?, ?> rc =
- CliUtil.executeFunction(this.undeployFunction, new Object[] {jars},
targetMembers);
- List<CliFunctionResult> results =
CliFunctionResult.cleanResults((List<?>) rc.getResult());
+ if (targetMembers.isEmpty()) {
+ return ResultModel.createError(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
+ }
- for (CliFunctionResult result : results) {
+ List<CliFunctionResult> results =
+ executeAndGetFunctionResult(this.undeployFunction, new Object[]
{jars}, targetMembers);
- if (result.getThrowable() != null) {
- tabularData.accumulate("Member", result.getMemberIdOrName());
- tabularData.accumulate("Un-Deployed JAR", "");
- tabularData.accumulate("Un-Deployed JAR Location",
- "ERROR: " + result.getThrowable().getClass().getName() + ": "
- + result.getThrowable().getMessage());
- accumulatedData = true;
- tabularData.setStatus(Result.Status.ERROR);
- } else {
- String[] strings = (String[]) result.getSerializables();
- for (int i = 0; i < strings.length; i += 2) {
- tabularData.accumulate("Member", result.getMemberIdOrName());
- tabularData.accumulate("Un-Deployed JAR", strings[i]);
- tabularData.accumulate("Un-Deployed From JAR Location", strings[i
+ 1]);
- accumulatedData = true;
- }
- }
+ ResultModel result = new ResultModel();
+ TabularResultModel tabularData = result.addTable("jars");
+ for (CliFunctionResult cliResult : results) {
+ if (!cliResult.isSuccessful()) {
+ result.setStatus(Result.Status.ERROR);
}
- if (!accumulatedData) {
- return
ResultBuilder.createInfoResult(CliStrings.UNDEPLOY__NO_JARS_FOUND_MESSAGE);
+ Map<String, String> undeployedJars = (Map<String, String>)
cliResult.getResultObject();
+ if (undeployedJars == null) {
+ continue;
}
- Result result = ResultBuilder.buildResult(tabularData);
- if (tabularData.getStatus().equals(Result.Status.OK)) {
- persistClusterConfiguration(result,
- () -> ((InternalConfigurationPersistenceService)
getConfigurationPersistenceService())
- .removeJars(jars, groups));
+ for (String key : undeployedJars.keySet()) {
+ tabularData.accumulate("Member", cliResult.getMemberIdOrName());
+ tabularData.accumulate("Un-Deployed JAR", key);
+ tabularData.accumulate("Un-Deployed From JAR Location",
undeployedJars.get(key));
}
+ }
+
+ if (tabularData.getRowSize() == 0) {
+ return
ResultModel.createInfo(CliStrings.UNDEPLOY__NO_JARS_FOUND_MESSAGE);
+ }
+
+ if (result.getStatus() != Result.Status.OK) {
return result;
- } catch (VirtualMachineError e) {
- SystemFailure.initiateFailure(e);
- throw e;
- } catch (Throwable th) {
- SystemFailure.checkFailure();
- return ResultBuilder.createGemFireErrorResult("Exception while
attempting to un-deploy: "
- + th.getClass().getName() + ": " + th.getMessage());
}
+ if (getConfigurationPersistenceService() == null) {
+
result.addInfo().addLine(CommandExecutor.SERVICE_NOT_RUNNING_CHANGE_NOT_PERSISTED);
+ } else {
+ ((InternalConfigurationPersistenceService)
getConfigurationPersistenceService())
+ .removeJars(jars, groups);
+ }
+
+ return result;
}
}
diff --git
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ListDeployedFunction.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ListDeployedFunction.java
index 2734df5..dc90344 100644
---
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ListDeployedFunction.java
+++
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ListDeployedFunction.java
@@ -14,12 +14,12 @@
*/
package org.apache.geode.management.internal.cli.functions;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.apache.logging.log4j.Logger;
-import org.apache.geode.SystemFailure;
-import org.apache.geode.cache.CacheClosedException;
import org.apache.geode.cache.execute.FunctionContext;
import org.apache.geode.distributed.DistributedMember;
import org.apache.geode.internal.ClassPathLoader;
@@ -54,28 +54,17 @@ public class ListDeployedFunction implements
InternalFunction {
}
final List<DeployedJar> jarClassLoaders = jarDeployer.findDeployedJars();
- final String[] jars = new String[jarClassLoaders.size() * 2];
- int index = 0;
+ final Map<String, String> jars = new HashMap<>();
for (DeployedJar jarClassLoader : jarClassLoaders) {
- jars[index++] = jarClassLoader.getJarName();
- jars[index++] = jarClassLoader.getFileCanonicalPath();
+ jars.put(jarClassLoader.getJarName(),
jarClassLoader.getFileCanonicalPath());
}
- CliFunctionResult result = new CliFunctionResult(memberId, jars);
+ CliFunctionResult result = new CliFunctionResult(memberId, jars, null);
context.getResultSender().lastResult(result);
- } catch (CacheClosedException cce) {
- CliFunctionResult result = new CliFunctionResult(memberId, false, null);
- context.getResultSender().lastResult(result);
-
- } catch (VirtualMachineError e) {
- SystemFailure.initiateFailure(e);
- throw e;
-
- } catch (Throwable th) {
- SystemFailure.checkFailure();
- logger.error("Could not list JAR files: {}", th.getMessage(), th);
- CliFunctionResult result = new CliFunctionResult(memberId, th, null);
+ } catch (Exception cce) {
+ logger.error(cce.getMessage(), cce);
+ CliFunctionResult result = new CliFunctionResult(memberId, false,
cce.getMessage());
context.getResultSender().lastResult(result);
}
}
diff --git
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ListFunctionFunction.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ListFunctionFunction.java
index 65c311c..87788de 100644
---
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ListFunctionFunction.java
+++
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ListFunctionFunction.java
@@ -14,17 +14,15 @@
*/
package org.apache.geode.management.internal.cli.functions;
-import java.util.LinkedList;
-import java.util.List;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.logging.log4j.Logger;
-import org.apache.geode.SystemFailure;
import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.CacheClosedException;
import org.apache.geode.cache.execute.Function;
import org.apache.geode.cache.execute.FunctionContext;
import org.apache.geode.cache.execute.FunctionService;
@@ -60,32 +58,23 @@ public class ListFunctionFunction implements
InternalFunction {
final Map<String, Function> functions =
FunctionService.getRegisteredFunctions();
CliFunctionResult result;
if (stringPattern == null || stringPattern.isEmpty()) {
- result = new CliFunctionResult(memberId,
functions.keySet().toArray(new String[0]));
+ result = new CliFunctionResult(memberId, new
HashSet(functions.keySet()), null);
} else {
Pattern pattern = Pattern.compile(stringPattern);
- List<String> resultList = new LinkedList<String>();
+ Set<String> resultSet = new HashSet<>();
for (String functionId : functions.keySet()) {
Matcher matcher = pattern.matcher(functionId);
if (matcher.matches()) {
- resultList.add(functionId);
+ resultSet.add(functionId);
}
}
- result = new CliFunctionResult(memberId, resultList.toArray(new
String[0]));
+ result = new CliFunctionResult(memberId, resultSet, null);
}
context.getResultSender().lastResult(result);
- } catch (CacheClosedException cce) {
- CliFunctionResult result = new CliFunctionResult(memberId, false, null);
- context.getResultSender().lastResult(result);
-
- } catch (VirtualMachineError e) {
- SystemFailure.initiateFailure(e);
- throw e;
-
- } catch (Throwable th) {
- SystemFailure.checkFailure();
- logger.error("Could not list functions: {}", th.getMessage(), th);
- CliFunctionResult result = new CliFunctionResult(memberId, th, null);
+ } catch (Exception cce) {
+ logger.error(cce.getMessage(), cce);
+ CliFunctionResult result = new CliFunctionResult(memberId, false,
cce.getMessage());
context.getResultSender().lastResult(result);
}
}
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 1d818ca..3792b59 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
@@ -14,14 +14,16 @@
*/
package org.apache.geode.management.internal.cli.functions;
-import java.util.ArrayList;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.logging.log4j.Logger;
-import org.apache.geode.SystemFailure;
-import org.apache.geode.cache.CacheClosedException;
import org.apache.geode.cache.execute.FunctionContext;
import org.apache.geode.distributed.DistributedMember;
import org.apache.geode.internal.ClassPathLoader;
@@ -58,52 +60,37 @@ public class UndeployFunction implements InternalFunction {
memberId = member.getName();
}
- String[] undeployedJars = new String[0];
- if (ArrayUtils.isEmpty(jarFilenameList)) {
- final List<DeployedJar> jarClassLoaders =
jarDeployer.findDeployedJars();
- undeployedJars = new String[jarClassLoaders.size() * 2];
- int index = 0;
- for (DeployedJar jarClassLoader : jarClassLoaders) {
- undeployedJars[index++] = jarClassLoader.getJarName();
- try {
- undeployedJars[index++] =
-
ClassPathLoader.getLatest().getJarDeployer().undeploy(jarClassLoader.getJarName());
- } catch (IllegalArgumentException iaex) {
- // It's okay for it to have have been uneployed from this server
- undeployedJars[index++] = iaex.getMessage();
- }
- }
+ List<String> jarNamesToUndeploy;
+ if (ArrayUtils.isNotEmpty(jarFilenameList)) {
+ jarNamesToUndeploy =
Arrays.stream(jarFilenameList).collect(Collectors.toList());
} else {
- List<String> undeployedList = new ArrayList<String>();
- for (String jarFilename : jarFilenameList) {
- try {
- undeployedList.add(jarFilename);
-
undeployedList.add(ClassPathLoader.getLatest().getJarDeployer().undeploy(jarFilename));
- } catch (IllegalArgumentException iaex) {
- // It's okay for it to not have been deployed to this server
- undeployedList.add(iaex.getMessage());
- }
+ final List<DeployedJar> jarClassLoaders =
jarDeployer.findDeployedJars();
+ jarNamesToUndeploy =
+ jarClassLoaders.stream().map(l ->
l.getJarName()).collect(Collectors.toList());
+ }
+
+ Map<String, String> undeployedJars = new HashMap<>();
+ for (String jarName : jarNamesToUndeploy) {
+ String jarLocation;
+ try {
+ jarLocation =
+ ClassPathLoader.getLatest().getJarDeployer().undeploy(jarName);
+ } catch (IOException | IllegalArgumentException iaex) {
+ // It's okay for it to have have been undeployed from this server
+ jarLocation = iaex.getMessage();
}
- undeployedJars = undeployedList.toArray(undeployedJars);
+ undeployedJars.put(jarName, jarLocation);
}
- CliFunctionResult result = new CliFunctionResult(memberId,
undeployedJars);
+ CliFunctionResult result = new CliFunctionResult(memberId,
undeployedJars, null);
context.getResultSender().lastResult(result);
- } catch (CacheClosedException cce) {
+ } catch (Exception cce) {
+ logger.error(cce.getMessage(), cce);
CliFunctionResult result = new CliFunctionResult(memberId, false, null);
context.getResultSender().lastResult(result);
-
- } catch (VirtualMachineError e) {
- SystemFailure.initiateFailure(e);
- throw e;
-
- } catch (Throwable th) {
- SystemFailure.checkFailure();
- logger.error("Could not undeploy JAR file: {}", th.getMessage(), th);
- CliFunctionResult result = new CliFunctionResult(memberId, th, null);
- context.getResultSender().lastResult(result);
}
+
}
@Override
diff --git
a/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/FunctionCommandsDUnitTestBase.java
b/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/FunctionCommandsDUnitTestBase.java
index cc2fd9a..c3879bb 100644
---
a/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/FunctionCommandsDUnitTestBase.java
+++
b/geode-dunit/src/main/java/org/apache/geode/management/internal/cli/commands/FunctionCommandsDUnitTestBase.java
@@ -136,7 +136,9 @@ public class FunctionCommandsDUnitTestBase {
public void testExecuteFunctionOnRegion() throws Exception {
gfsh.executeAndAssertThat(
"execute function --id=" + TEST_FUNCTION1 + " --region=/" +
REGION_ONE).statusIsSuccess()
- .tableHasColumnWithValuesContaining("Member", server1.getName(),
server2.getName());
+ .hasTableSection()
+ .hasRowSize(1)
+ .hasRowContaining("OK", "[false, false]");
}
@Test
@@ -157,14 +159,19 @@ public class FunctionCommandsDUnitTestBase {
"execute function --id=" + TEST_FUNCTION_RETURN_ARGS + " --region=" +
REGION_ONE
+ " --arguments=arg1" + " --result-collector=" +
ToUpperResultCollector.class.getName())
.statusIsSuccess()
- .tableHasColumnOnlyWithValues(RESULT_HEADER, "[ARG1, ARG1]", "[ARG1,
ARG1]");
+ .hasTableSection()
+ .hasRowSize(1)
+ .hasRowContaining("OK", "[ARG1, ARG1]");
}
@Test
public void testExecuteFunctionOnMember() {
gfsh.executeAndAssertThat(
"execute function --id=" + TEST_FUNCTION1 + " --member=" +
server1.getMember().getName())
- .statusIsSuccess().tableHasColumnWithValuesContaining("Member",
server1.getName());
+ .statusIsSuccess()
+ .hasTableSection()
+ .hasRowSize(1)
+ .hasRowContaining("server-1", "OK", "[false]");
}
@Test
@@ -176,16 +183,20 @@ public class FunctionCommandsDUnitTestBase {
@Test
public void testExecuteFunctionOnAllMembers() {
gfsh.executeAndAssertThat("execute function --id=" +
TEST_FUNCTION1).statusIsSuccess()
- .tableHasColumnWithValuesContaining("Member", server1.getName(),
server2.getName())
- .tableHasColumnWithExactValuesInAnyOrder(RESULT_HEADER, "[false]",
"[false]");
+ .hasTableSection()
+ .hasRowSize(2)
+ .hasRowContaining("server-1", "OK", "[false]")
+ .hasRowContaining("server-2", "OK", "[false]");
}
@Test
public void testExecuteFunctionOnMultipleMembers() {
gfsh.executeAndAssertThat("execute function --id=" + TEST_FUNCTION1 + "
--member="
+ Strings.join(server1.getName(),
server2.getName()).with(",")).statusIsSuccess()
- .tableHasColumnWithValuesContaining("Member", server1.getName(),
server2.getName())
- .tableHasColumnWithExactValuesInAnyOrder(RESULT_HEADER, "[false]",
"[false]");
+ .hasTableSection()
+ .hasRowSize(2)
+ .hasRowContaining("server-1", "OK", "[false]")
+ .hasRowContaining("server-2", "OK", "[false]");
}
@Test
@@ -193,23 +204,30 @@ public class FunctionCommandsDUnitTestBase {
gfsh.executeAndAssertThat("execute function --id=" +
TEST_FUNCTION_RETURN_ARGS
+ " --arguments=arg1" + " --result-collector=" +
ToUpperResultCollector.class.getName())
.statusIsSuccess()
- .tableHasColumnWithValuesContaining("Member", server1.getName(),
server2.getName())
- .tableHasColumnWithExactValuesInAnyOrder(RESULT_HEADER, "[ARG1]",
"[ARG1]");
+ .hasTableSection()
+ .hasRowSize(2)
+ .hasRowContaining("server-1", "OK", "[ARG1]")
+ .hasRowContaining("server-2", "OK", "[ARG1]");
}
@Test
public void testFunctionOnlyRegisteredOnOneMember() {
gfsh.executeAndAssertThat("execute function --id=" +
TEST_FUNCTION_ON_ONE_MEMBER_RETURN_ARGS)
- .tableHasColumnWithValuesContaining(RESULT_HEADER, "[false]",
- "Function : executeFunctionOnOneMemberToReturnArgs is not
registered on member.")
- .statusIsError();
+ .statusIsError()
+ .hasTableSection()
+ .hasRowSize(2)
+ .hasRowContaining("server-1", "OK", "[false]")
+ .hasRowContaining("server-2", "ERROR",
+ "Function : executeFunctionOnOneMemberToReturnArgs is not
registered on member.");
}
@Test
public void testExecuteFunctionOnGroup() {
gfsh.executeAndAssertThat("execute function --id=" + TEST_FUNCTION1 + "
--groups=group-1")
- .statusIsSuccess().tableHasColumnWithValuesContaining("Member",
server1.getName())
- .tableHasColumnWithExactValuesInAnyOrder(RESULT_HEADER, "[false]");
+ .statusIsSuccess()
+ .hasTableSection()
+ .hasRowSize(1)
+ .hasRowContaining("server-1", "OK", "[false]");
}
@Test
@@ -219,14 +237,18 @@ public class FunctionCommandsDUnitTestBase {
.statusIsSuccess();
gfsh.executeAndAssertThat("list functions").statusIsSuccess()
- .tableHasColumnWithExactValuesInAnyOrder("Function",
TEST_FUNCTION_RETURN_ARGS,
+ .hasTableSection()
+ .hasColumn("Function")
+ .containsExactlyInAnyOrder(TEST_FUNCTION_RETURN_ARGS,
TEST_FUNCTION1, TEST_FUNCTION_RETURN_ARGS,
TEST_FUNCTION_ALWAYS_THROWS_EXCEPTION,
TEST_FUNCTION_ALWAYS_THROWS_EXCEPTION,
TEST_FUNCTION_ON_ONE_MEMBER_RETURN_ARGS);
gfsh.executeAndAssertThat(
"destroy function --id=" + TEST_FUNCTION1 + " --member=" +
server2.getName())
.statusIsSuccess();
gfsh.executeAndAssertThat("list functions").statusIsSuccess()
- .tableHasColumnWithExactValuesInAnyOrder("Function",
TEST_FUNCTION_RETURN_ARGS,
+ .hasTableSection()
+ .hasColumn("Function")
+ .containsExactlyInAnyOrder(TEST_FUNCTION_RETURN_ARGS,
TEST_FUNCTION_RETURN_ARGS, TEST_FUNCTION_ALWAYS_THROWS_EXCEPTION,
TEST_FUNCTION_ALWAYS_THROWS_EXCEPTION,
TEST_FUNCTION_ON_ONE_MEMBER_RETURN_ARGS);
}
@@ -236,7 +258,9 @@ public class FunctionCommandsDUnitTestBase {
gfsh.executeAndAssertThat("destroy function --id=" + TEST_FUNCTION1 + "
--groups=group-1")
.statusIsSuccess();
gfsh.executeAndAssertThat("list functions").statusIsSuccess()
- .tableHasColumnWithExactValuesInAnyOrder("Function",
TEST_FUNCTION_RETURN_ARGS,
+ .hasTableSection()
+ .hasColumn("Function")
+ .contains(TEST_FUNCTION_RETURN_ARGS,
TEST_FUNCTION1, TEST_FUNCTION_RETURN_ARGS,
TEST_FUNCTION_ALWAYS_THROWS_EXCEPTION,
TEST_FUNCTION_ALWAYS_THROWS_EXCEPTION,
TEST_FUNCTION_ON_ONE_MEMBER_RETURN_ARGS);
}
@@ -244,29 +268,40 @@ public class FunctionCommandsDUnitTestBase {
@Test
public void testListFunctions() {
gfsh.executeAndAssertThat("list functions").statusIsSuccess()
- .tableHasColumnWithExactValuesInAnyOrder("Function", TEST_FUNCTION1,
TEST_FUNCTION1,
+ .hasTableSection()
+ .hasColumn("Function")
+ .containsExactlyInAnyOrder(TEST_FUNCTION1, TEST_FUNCTION1,
TEST_FUNCTION_RETURN_ARGS, TEST_FUNCTION_RETURN_ARGS,
TEST_FUNCTION_ALWAYS_THROWS_EXCEPTION,
TEST_FUNCTION_ALWAYS_THROWS_EXCEPTION,
TEST_FUNCTION_ON_ONE_MEMBER_RETURN_ARGS);
gfsh.executeAndAssertThat("list functions
--matches=Test.*").statusIsSuccess()
- .tableHasColumnWithExactValuesInAnyOrder("Function", TEST_FUNCTION1,
TEST_FUNCTION1,
+ .hasTableSection()
+ .hasColumn("Function")
+ .containsExactlyInAnyOrder(TEST_FUNCTION1, TEST_FUNCTION1,
TEST_FUNCTION_ALWAYS_THROWS_EXCEPTION,
TEST_FUNCTION_ALWAYS_THROWS_EXCEPTION);
gfsh.executeAndAssertThat("list functions --matches=Test.*
--groups=group-1").statusIsSuccess()
- .tableHasColumnWithExactValuesInAnyOrder("Function", TEST_FUNCTION1,
- TEST_FUNCTION_ALWAYS_THROWS_EXCEPTION);
+ .hasTableSection()
+ .hasColumn("Function")
+ .containsExactlyInAnyOrder(TEST_FUNCTION1,
TEST_FUNCTION_ALWAYS_THROWS_EXCEPTION);
gfsh.executeAndAssertThat("list functions --matches=Test.* --members=" +
server1.getName())
- .statusIsSuccess().tableHasColumnWithExactValuesInAnyOrder("Function",
TEST_FUNCTION1,
- TEST_FUNCTION_ALWAYS_THROWS_EXCEPTION);
+ .statusIsSuccess()
+ .hasTableSection()
+ .hasColumn("Function")
+ .containsExactlyInAnyOrder(TEST_FUNCTION1,
TEST_FUNCTION_ALWAYS_THROWS_EXCEPTION);
}
@Test
public void testFunctionException() {
+ String errorMessage =
+ "Exception:
org.apache.geode.internal.cache.execute.MyFunctionExecutionException: I have
been thrown from TestFunction";
gfsh.executeAndAssertThat("execute function --id=" +
TEST_FUNCTION_ALWAYS_THROWS_EXCEPTION)
- .tableHasColumnWithValuesContaining(RESULT_HEADER, "I have been thrown
from TestFunction",
- "I have been thrown from TestFunction")
- .statusIsError();
+ .statusIsError()
+ .hasTableSection()
+ .hasRowSize(2)
+ .hasRowContaining("server-1", "ERROR", errorMessage)
+ .hasRowContaining("server-2", "ERROR", errorMessage);
}
}