Search in sources :

Example 36 with SectionResultData

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"));
    }
}
Also used : SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) ParseResult(org.springframework.shell.event.ParseResult) GfshParseResult(org.apache.geode.management.internal.cli.GfshParseResult) Result(org.apache.geode.management.cli.Result)

Example 37 with SectionResultData

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());
        }
    }
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult)

Example 38 with SectionResultData

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());
        }
    }
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult)

Example 39 with SectionResultData

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;
    }
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)

Example 40 with SectionResultData

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);
    }
}
Also used : GfJsonArray(org.apache.geode.management.internal.cli.json.GfJsonArray) CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)

Aggregations

SectionResultData (org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)44 CompositeResultData (org.apache.geode.management.internal.cli.result.CompositeResultData)38 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)22 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)10 InternalCache (org.apache.geode.internal.cache.InternalCache)9 Result (org.apache.geode.management.cli.Result)9 DistributedMember (org.apache.geode.distributed.DistributedMember)8 CliMetaData (org.apache.geode.management.cli.CliMetaData)8 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)8 CliCommand (org.springframework.shell.core.annotation.CliCommand)8 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)7 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)7 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)7 Test (org.junit.Test)7 ObjectName (javax.management.ObjectName)6 SystemManagementService (org.apache.geode.management.internal.SystemManagementService)6 CacheServerMXBean (org.apache.geode.management.CacheServerMXBean)5 HashMap (java.util.HashMap)4 List (java.util.List)4