use of org.apache.geode.management.internal.cli.result.ErrorResultData in project geode by apache.
the class ConfigCommands method describeConfig.
@CliCommand(value = { CliStrings.DESCRIBE_CONFIG }, help = CliStrings.DESCRIBE_CONFIG__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_CONFIG })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result describeConfig(@CliOption(key = CliStrings.DESCRIBE_CONFIG__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) {
Result result = null;
try {
DistributedMember targetMember = null;
if (memberNameOrId != null && !memberNameOrId.isEmpty()) {
targetMember = CliUtil.getDistributedMemberByNameOrId(memberNameOrId);
}
if (targetMember != null) {
ResultCollector<?, ?> rc = CliUtil.executeFunction(getMemberConfigFunction, new Boolean(hideDefaults), targetMember);
ArrayList<?> output = (ArrayList<?>) rc.getResult();
Object obj = output.get(0);
if (obj != null && obj instanceof MemberConfigurationInfo) {
MemberConfigurationInfo memberConfigInfo = (MemberConfigurationInfo) obj;
CompositeResultData crd = ResultBuilder.createCompositeResultData();
crd.setHeader(CliStrings.format(CliStrings.DESCRIBE_CONFIG__HEADER__TEXT, memberNameOrId));
List<String> jvmArgsList = memberConfigInfo.getJvmInputArguments();
TabularResultData jvmInputArgs = crd.addSection().addSection().addTable();
for (String jvmArg : jvmArgsList) {
jvmInputArgs.accumulate("JVM command line arguments", jvmArg);
}
addSection(crd, memberConfigInfo.getGfePropsSetUsingApi(), "GemFire properties defined using the API");
addSection(crd, memberConfigInfo.getGfePropsRuntime(), "GemFire properties defined at the runtime");
addSection(crd, memberConfigInfo.getGfePropsSetFromFile(), "GemFire properties defined with the property file");
addSection(crd, memberConfigInfo.getGfePropsSetWithDefaults(), "GemFire properties using default values");
addSection(crd, memberConfigInfo.getCacheAttributes(), "Cache attributes");
List<Map<String, String>> cacheServerAttributesList = memberConfigInfo.getCacheServerAttributes();
if (cacheServerAttributesList != null && !cacheServerAttributesList.isEmpty()) {
SectionResultData cacheServerSection = crd.addSection();
cacheServerSection.setHeader("Cache-server attributes");
for (Map<String, String> cacheServerAttributes : cacheServerAttributesList) {
addSubSection(cacheServerSection, cacheServerAttributes, "");
}
}
result = ResultBuilder.buildResult(crd);
}
} else {
ErrorResultData erd = ResultBuilder.createErrorResultData();
erd.addLine(CliStrings.format(CliStrings.DESCRIBE_CONFIG__MEMBER__NOT__FOUND, new Object[] { memberNameOrId }));
result = ResultBuilder.buildResult(erd);
}
} catch (FunctionInvocationTargetException e) {
result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.COULD_NOT_EXECUTE_COMMAND_TRY_AGAIN, CliStrings.DESCRIBE_CONFIG));
} catch (Exception e) {
ErrorResultData erd = ResultBuilder.createErrorResultData();
erd.addLine(e.getMessage());
result = ResultBuilder.buildResult(erd);
}
return result;
}
use of org.apache.geode.management.internal.cli.result.ErrorResultData in project geode by apache.
the class GfshCommandsSecurityTest method runCommandsWithAndWithout.
private void runCommandsWithAndWithout(String permission) throws Exception {
List<TestCommand> allPermitted = TestCommand.getPermittedCommands(new WildcardPermission(permission, true));
for (TestCommand permitted : allPermitted) {
System.out.println("Processing authorized command: " + permitted.getCommand());
CommandResult result = gfshConnection.executeCommand(permitted.getCommand());
assertNotNull(result);
if (result.getResultData() instanceof ErrorResultData) {
assertNotEquals(ResultBuilder.ERRORCODE_UNAUTHORIZED, ((ErrorResultData) result.getResultData()).getErrorCode());
} else {
assertEquals(Result.Status.OK, result.getStatus());
}
}
List<TestCommand> others = TestCommand.getCommands();
others.removeAll(allPermitted);
for (TestCommand other : others) {
// skip no permission commands
if (other.getPermission() == null)
continue;
System.out.println("Processing unauthorized command: " + other.getCommand());
CommandResult result = (CommandResult) gfshConnection.executeCommand(other.getCommand());
int errorCode = ((ErrorResultData) result.getResultData()).getErrorCode();
// those commands
if (errorCode == ResultBuilder.ERRORCODE_USER_ERROR) {
LogService.getLogger().info("Skip user error: " + result.getContent());
continue;
}
assertEquals(ResultBuilder.ERRORCODE_UNAUTHORIZED, ((ErrorResultData) result.getResultData()).getErrorCode());
String resultMessage = result.getContent().toString();
String permString = other.getPermission().toString();
assertTrue(resultMessage + " does not contain " + permString, resultMessage.contains(permString));
}
}
use of org.apache.geode.management.internal.cli.result.ErrorResultData in project geode by apache.
the class MultiUserDUnitTest method testMultiUser.
// GEODE-1579
@Category(FlakyTest.class)
@Test
public void testMultiUser() throws IOException, JSONException, InterruptedException {
IgnoredException.addIgnoredException("java.util.zip.ZipException: zip file is empty");
Properties properties = new Properties();
properties.put(NAME, MultiUserDUnitTest.class.getSimpleName());
properties.put(SECURITY_MANAGER, TestSecurityManager.class.getName());
// set up vm_0 the secure jmx manager
Object[] results = setUpJMXManagerOnVM(0, properties, "org/apache/geode/management/internal/security/cacheServer.json");
String gfshDir = this.gfshDir;
// set up vm_1 as a gfsh vm, data-reader will login and log out constantly in this vm until the
// test is done.
VM vm1 = Host.getHost(0).getVM(1);
AsyncInvocation vm1Invoke = vm1.invokeAsync("run as data-reader", () -> {
String shellId = getClass().getSimpleName() + "_vm1";
HeadlessGfsh shell = new HeadlessGfsh(shellId, 30, gfshDir);
while (true) {
connect((String) results[0], (Integer) results[1], (Integer) results[2], shell, "data-reader", "1234567");
Awaitility.waitAtMost(5, TimeUnit.MILLISECONDS);
shell.executeCommand("disconnect");
}
});
VM vm2 = Host.getHost(0).getVM(2);
// set up vm_2 as a gfsh vm, and then connect as "stranger" and try to execute the commands and
// assert errors comes back are NotAuthorized
AsyncInvocation vm2Invoke = vm2.invokeAsync("run as guest", () -> {
String shellId = getClass().getSimpleName() + "_vm2";
HeadlessGfsh shell = new HeadlessGfsh(shellId, 30, gfshDir);
connect((String) results[0], (Integer) results[1], (Integer) results[2], shell, "stranger", "1234567");
List<TestCommand> allCommands = TestCommand.getCommands();
for (TestCommand command : allCommands) {
LogService.getLogger().info("executing: " + command.getCommand());
if (command.getPermission() == null) {
continue;
}
CommandResult result = executeCommand(shell, command.getCommand());
int errorCode = ((ErrorResultData) result.getResultData()).getErrorCode();
// those commands
if (errorCode == ResultBuilder.ERRORCODE_USER_ERROR) {
LogService.getLogger().info("Skip user error: " + result.getContent());
continue;
}
assertEquals("Not an expected result: " + result.toString(), ResultBuilder.ERRORCODE_UNAUTHORIZED, ((ErrorResultData) result.getResultData()).getErrorCode());
String resultMessage = result.getContent().toString();
String permString = command.getPermission().toString();
assertTrue(resultMessage + " does not contain " + permString, resultMessage.contains(permString));
}
LogService.getLogger().info("vm 2 done!");
});
VM vm3 = Host.getHost(0).getVM(3);
IgnoredException.addIgnoredException("java.lang.IllegalArgumentException: Region doesnt exist: {0}", vm3);
IgnoredException.addIgnoredException("java.lang.ClassNotFoundException: myApp.myListener", vm3);
// set up vm_3 as another gfsh vm, and then connect as "super-user" and try to execute the
// commands and assert we don't get a NotAuthorized Exception
AsyncInvocation vm3Invoke = vm3.invokeAsync("run as superUser", () -> {
String shellId = getClass().getSimpleName() + "_vm3";
HeadlessGfsh shell = new HeadlessGfsh(shellId, 30, gfshDir);
connect((String) results[0], (Integer) results[1], (Integer) results[2], shell, "super-user", "1234567");
List<TestCommand> allCommands = TestCommand.getCommands();
for (TestCommand command : allCommands) {
LogService.getLogger().info("executing: " + command.getCommand());
if (command.getPermission() == null) {
continue;
}
CommandResult result = executeCommand(shell, command.getCommand());
if (result.getResultData().getStatus() == Status.OK) {
continue;
}
assertNotEquals("Did not expect an Unauthorized exception: " + result.toString(), ResultBuilder.ERRORCODE_UNAUTHORIZED, ((ErrorResultData) result.getResultData()).getErrorCode());
}
LogService.getLogger().info("vm 3 done!");
});
// only wait until vm2 and vm3 are done. vm1 will close when test finishes
vm2Invoke.join();
vm3Invoke.join();
vm2Invoke.checkException();
vm3Invoke.checkException();
IgnoredException.removeAllExpectedExceptions();
}
use of org.apache.geode.management.internal.cli.result.ErrorResultData in project geode by apache.
the class DurableClientCommands method buildFailureData.
private ErrorResultData buildFailureData(Map<String, List<String>> successMap, Map<String, List<String>> exceptionMap, Map<String, List<String>> errorMap, String errorHeader) {
ErrorResultData erd = ResultBuilder.createErrorResultData();
buildErrorResult(erd, successMap);
erd.addLine("\n");
erd.addLine(errorHeader);
buildErrorResult(erd, exceptionMap);
buildErrorResult(erd, errorMap);
return erd;
}
use of org.apache.geode.management.internal.cli.result.ErrorResultData in project geode by apache.
the class FunctionCommands method executeFunction.
Result executeFunction(InternalCache cache, Set<DistributedMember> DsMembers, String functionId) {
// unregister on a set of of members
Function unregisterFunction = new UnregisterFunction();
FunctionService.registerFunction(unregisterFunction);
List resultList = null;
if (DsMembers.isEmpty()) {
return ResultBuilder.createInfoResult("No members for execution");
}
Object[] obj = new Object[1];
obj[0] = functionId;
Execution execution = FunctionService.onMembers(DsMembers).setArguments(obj);
if (execution == null) {
cache.getLogger().error("executeUnregister execution is null");
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(CliStrings.DESTROY_FUNCTION__MSG__CANNOT_EXECUTE);
return (ResultBuilder.buildResult(errorResultData));
}
try {
resultList = (ArrayList) execution.execute(unregisterFunction).getResult();
} catch (FunctionException ex) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(ex.getMessage());
return (ResultBuilder.buildResult(errorResultData));
}
String resultStr = ((String) resultList.get(0));
if (resultStr.equals("Succeeded in unregistering")) {
StringBuilder members = new StringBuilder();
for (DistributedMember member : DsMembers) {
members.append(member.getId());
members.append(",");
}
return ResultBuilder.createInfoResult("Destroyed " + functionId + " Successfully on " + members.toString().substring(0, members.toString().length() - 1));
} else {
return ResultBuilder.createInfoResult("Failed in unregistering");
}
}
Aggregations