use of org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData in project geode by apache.
the class CLIMultiStepHelper method execCLISteps.
public static Result execCLISteps(LogWrapper logWrapper, Gfsh shell, ParseResult parseResult) {
CLIStep[] steps = (CLIStep[]) ReflectionUtils.invokeMethod(parseResult.getMethod(), parseResult.getInstance(), parseResult.getArguments());
if (steps != null) {
boolean endStepReached = false;
int stepNumber = 0;
CLIStep nextStep = steps[stepNumber];
Result lastResult = null;
SectionResultData nextStepArgs = null;
while (!endStepReached) {
try {
Result result = executeStep(logWrapper, shell, nextStep, parseResult, nextStepArgs);
String nextStepString = null;
nextStepString = getNextStep(result);
nextStepArgs = extractArgumentsForNextStep(result);
if (!"END".equals(nextStepString)) {
String step = nextStepString;
boolean stepFound = false;
for (CLIStep s : steps) if (step.equals(s.getName())) {
nextStep = s;
stepFound = true;
}
if (!stepFound) {
return ResultBuilder.buildResult(ResultBuilder.createErrorResultData().addLine("Wrong step name returned by previous step : " + step));
}
} else {
lastResult = result;
endStepReached = true;
}
} catch (CLIStepExecption e) {
endStepReached = true;
lastResult = e.getResult();
}
}
return lastResult;
} else {
Gfsh.println("Command returned null steps");
return ResultBuilder.buildResult(ResultBuilder.createErrorResultData().addLine("Multi-step command Return NULL STEP Array"));
}
}
use of org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData in project geode by apache.
the class CLIMultiStepHelper method getNextStep.
public static String getNextStep(Result cdata) {
CommandResult cResult = (CommandResult) cdata;
if (ResultData.TYPE_COMPOSITE.equals(cResult.getType())) {
CompositeResultData rd = (CompositeResultData) cResult.getResultData();
SectionResultData section = rd.retrieveSection(CLIMultiStepHelper.STEP_SECTION);
String nextStep = (String) section.retrieveObject(CLIMultiStepHelper.NEXT_STEP_NAME);
return nextStep;
} else {
if (ResultData.TYPE_ERROR.equals(cResult.getType())) {
throw new CLIStepExecption(cResult);
} else {
throw new RuntimeException("Step returned result of type other than " + ResultData.TYPE_COMPOSITE + " Type " + cResult.getType());
}
}
}
use of org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData in project geode by apache.
the class CLIMultiStepHelper method extractArgumentsForNextStep.
public static SectionResultData extractArgumentsForNextStep(Result result) {
CommandResult cResult = (CommandResult) result;
if (ResultData.TYPE_COMPOSITE.equals(cResult.getType())) {
CompositeResultData rd = (CompositeResultData) cResult.getResultData();
SectionResultData data = rd.retrieveSection(CLIMultiStepHelper.ARG_SECTION);
return data;
} else {
if (ResultData.TYPE_ERROR.equals(cResult.getType())) {
throw new CLIStepExecption(cResult);
} else {
throw new StepExecutionException("Step returned result of type other than " + ResultData.TYPE_COMPOSITE + " Type " + cResult.getType());
}
}
}
use of org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData in project geode by apache.
the class DataCommandResult method toSelectCommandResult.
/**
* This method returns result when flag interactive=false i.e. Command returns result in one go
* and does not goes through steps waiting for user input. Method returns CompositeResultData
* instead of Result as Command Step is required to add NEXT_STEP information to guide
* executionStragey to route it through final step.
*/
public CompositeResultData toSelectCommandResult() {
if (errorString != null) {
// return ResultBuilder.createGemFireErrorResult(errorString);
CompositeResultData data = ResultBuilder.createCompositeResultData();
SectionResultData section = data.addSection();
section.addData("Message", errorString);
section.addData(RESULT_FLAG, operationCompletedSuccessfully);
return data;
} else {
CompositeResultData data = ResultBuilder.createCompositeResultData();
SectionResultData section = data.addSection();
TabularResultData table = section.addTable();
section.addData(RESULT_FLAG, operationCompletedSuccessfully);
if (infoString != null) {
section.addData("Message", infoString);
}
if (inputQuery != null) {
if (this.limit != -1) {
section.addData("Limit", this.limit);
}
if (this.selectResult != null) {
section.addData(NUM_ROWS, this.selectResult.size());
if (this.queryTraceString != null) {
section.addData("Query Trace", this.queryTraceString);
}
buildTable(table, 0, selectResult.size());
}
}
return data;
}
}
use of org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData in project geode by apache.
the class GemfireDataCommandsDUnitTest method validateJSONGetResult.
private void validateJSONGetResult(CommandResult cmdResult, String[] expectedCols) {
CompositeResultData rd = (CompositeResultData) cmdResult.getResultData();
SectionResultData section = rd.retrieveSectionByIndex(0);
TabularResultData table = section.retrieveTableByIndex(0);
GfJsonArray array = table.getHeaders();
assertEquals(expectedCols.length, array.size());
try {
for (String col : expectedCols) {
boolean found = false;
getLogWriter().info("Validating column " + col);
for (int i = 0; i < array.size(); i++) {
String header = (String) array.get(i);
if (col.equals(header))
found = true;
}
assertEquals(true, found);
}
} catch (GfJsonException e) {
fail("Error accessing table data", e);
}
}
Aggregations