use of org.springframework.shell.event.ParseResult in project geode by apache.
the class CommandProcessor method executeCommand.
public Result executeCommand(CommandStatement cmdStmt) {
Object result = null;
Result commandResult = null;
CommentSkipHelper commentSkipper = new CommentSkipHelper();
String commentLessLine = commentSkipper.skipComments(cmdStmt.getCommandString());
if (commentLessLine != null && !commentLessLine.isEmpty()) {
CommandExecutionContext.setShellEnv(cmdStmt.getEnv());
final RemoteExecutionStrategy executionStrategy = getExecutionStrategy();
try {
ParseResult parseResult = ((CommandStatementImpl) cmdStmt).getParseResult();
if (parseResult == null) {
parseResult = parseCommand(commentLessLine);
if (parseResult == null) {
// TODO-Abhishek: Handle this in GfshParser Implementation
setLastExecutionStatus(1);
return ResultBuilder.createParsingErrorResult(cmdStmt.getCommandString());
}
((CommandStatementImpl) cmdStmt).setParseResult(parseResult);
}
// do general authorization check here
Method method = parseResult.getMethod();
ResourceOperation resourceOperation = method.getAnnotation(ResourceOperation.class);
this.securityService.authorize(resourceOperation);
result = executionStrategy.execute(parseResult);
if (result instanceof Result) {
commandResult = (Result) result;
} else {
if (logWrapper.fineEnabled()) {
logWrapper.fine("Unknown result type, using toString : " + String.valueOf(result));
}
commandResult = ResultBuilder.createInfoResult(String.valueOf(result));
}
} catch (CommandProcessingException e) {
// expected from Parser
setLastExecutionStatus(1);
if (logWrapper.infoEnabled()) {
logWrapper.info("Could not parse \"" + cmdStmt.getCommandString() + "\".", e);
}
return ResultBuilder.createParsingErrorResult(e.getMessage());
} catch (NotAuthorizedException e) {
setLastExecutionStatus(1);
if (logWrapper.infoEnabled()) {
logWrapper.info("Could not execute \"" + cmdStmt.getCommandString() + "\".", e);
}
// for NotAuthorizedException, will catch this later in the code
throw e;
} catch (RuntimeException e) {
setLastExecutionStatus(1);
if (logWrapper.infoEnabled()) {
logWrapper.info("Could not execute \"" + cmdStmt.getCommandString() + "\".", e);
}
return ResultBuilder.createGemFireErrorResult("Error while processing command <" + cmdStmt.getCommandString() + "> Reason : " + e.getMessage());
} catch (Exception e) {
setLastExecutionStatus(1);
if (logWrapper.warningEnabled()) {
logWrapper.warning("Could not execute \"" + cmdStmt.getCommandString() + "\".", e);
}
return ResultBuilder.createGemFireErrorResult("Unexpected error while processing command <" + cmdStmt.getCommandString() + "> Reason : " + e.getMessage());
}
if (logWrapper.fineEnabled()) {
logWrapper.fine("Executed " + commentLessLine);
}
setLastExecutionStatus(0);
}
return commandResult;
}
use of org.springframework.shell.event.ParseResult in project geode by apache.
the class GfshParserParsingTest method parseParams.
private Map<String, String> parseParams(String input, String commandMethod) {
ParseResult parseResult = parser.parse(input);
GfshParseResult gfshParseResult = (GfshParseResult) parseResult;
Map<String, String> params = gfshParseResult.getParamValueStrings();
for (String param : params.keySet()) {
System.out.println(param + "=" + params.get(param));
}
assertThat(gfshParseResult.getMethod().getName()).isEqualTo(commandMethod);
assertThat(gfshParseResult.getUserInput()).isEqualTo(input.trim());
return params;
}
use of org.springframework.shell.event.ParseResult in project geode by apache.
the class GfshParserConverterTest method testUnspecifiedValueToStringArray.
@Test
public void testUnspecifiedValueToStringArray() {
String command = "change loglevel --loglevel=finer --groups=group1,group2";
ParseResult result = parser.parse(command);
String[] memberIdValue = (String[]) result.getArguments()[0];
assertThat(memberIdValue).isNull();
}
Aggregations