Search in sources :

Example 1 with ResultDataException

use of org.apache.geode.management.internal.cli.result.ResultDataException in project geode by apache.

the class JsonUtil method getStringArray.

public static String[] getStringArray(GfJsonObject jsonObject, String byName) {
    String[] stringArray = null;
    try {
        GfJsonArray jsonArray = jsonObject.getJSONArray(byName);
        stringArray = GfJsonArray.toStringArray(jsonArray);
    } catch (GfJsonException e) {
        throw new ResultDataException(e.getMessage());
    }
    return stringArray;
}
Also used : GfJsonArray(org.apache.geode.management.internal.cli.json.GfJsonArray) ResultDataException(org.apache.geode.management.internal.cli.result.ResultDataException) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException)

Example 2 with ResultDataException

use of org.apache.geode.management.internal.cli.result.ResultDataException in project geode by apache.

the class JsonUtil method getList.

public static List<CliJsonSerializable> getList(GfJsonObject jsonObject, String byName) {
    List<CliJsonSerializable> cliJsonSerializables = Collections.emptyList();
    try {
        GfJsonArray cliJsonSerializableArray = jsonObject.getJSONArray(byName);
        int size = cliJsonSerializableArray.size();
        if (size > 0) {
            cliJsonSerializables = new ArrayList<CliJsonSerializable>();
        }
        for (int i = 0; i < size; i++) {
            GfJsonObject cliJsonSerializableState = cliJsonSerializableArray.getJSONObject(i);
            int jsId = cliJsonSerializableState.getInt(CliJsonSerializable.JSID);
            CliJsonSerializable cliJsonSerializable = CliJsonSerializableFactory.getCliJsonSerializable(jsId);
            cliJsonSerializable.fromJson(cliJsonSerializableState);
            cliJsonSerializables.add(cliJsonSerializable);
        }
    } catch (GfJsonException e) {
        throw new ResultDataException(e.getMessage());
    }
    return cliJsonSerializables;
}
Also used : GfJsonArray(org.apache.geode.management.internal.cli.json.GfJsonArray) GfJsonObject(org.apache.geode.management.internal.cli.json.GfJsonObject) ResultDataException(org.apache.geode.management.internal.cli.result.ResultDataException) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException) CliJsonSerializable(org.apache.geode.management.internal.cli.result.CliJsonSerializable)

Example 3 with ResultDataException

use of org.apache.geode.management.internal.cli.result.ResultDataException in project geode by apache.

the class JsonUtil method getSet.

public static Set<CliJsonSerializable> getSet(GfJsonObject jsonObject, String byName) {
    Set<CliJsonSerializable> cliJsonSerializables = Collections.emptySet();
    try {
        GfJsonArray cliJsonSerializableArray = jsonObject.getJSONArray(byName);
        int size = cliJsonSerializableArray.size();
        if (size > 0) {
            cliJsonSerializables = new HashSet<CliJsonSerializable>();
        }
        for (int i = 0; i < size; i++) {
            GfJsonObject cliJsonSerializableState = cliJsonSerializableArray.getJSONObject(i);
            int jsId = cliJsonSerializableState.getInt(CliJsonSerializable.JSID);
            CliJsonSerializable cliJsonSerializable = CliJsonSerializableFactory.getCliJsonSerializable(jsId);
            cliJsonSerializable.fromJson(cliJsonSerializableState);
            cliJsonSerializables.add(cliJsonSerializable);
        }
    } catch (GfJsonException e) {
        throw new ResultDataException(e.getMessage());
    }
    return cliJsonSerializables;
}
Also used : GfJsonArray(org.apache.geode.management.internal.cli.json.GfJsonArray) GfJsonObject(org.apache.geode.management.internal.cli.json.GfJsonObject) ResultDataException(org.apache.geode.management.internal.cli.result.ResultDataException) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException) CliJsonSerializable(org.apache.geode.management.internal.cli.result.CliJsonSerializable)

Example 4 with ResultDataException

use of org.apache.geode.management.internal.cli.result.ResultDataException in project geode by apache.

the class DiskStoreCommands method toMissingDiskStoresTabularResult.

protected Result toMissingDiskStoresTabularResult(final List<Object> resultDetails) throws ResultDataException {
    CompositeResultData crd = ResultBuilder.createCompositeResultData();
    List<PersistentMemberPattern> missingDiskStores = new ArrayList<PersistentMemberPattern>();
    List<ColocatedRegionDetails> missingColocatedRegions = new ArrayList<ColocatedRegionDetails>();
    for (Object detail : resultDetails) {
        if (detail instanceof PersistentMemberPattern) {
            missingDiskStores.add((PersistentMemberPattern) detail);
        } else if (detail instanceof ColocatedRegionDetails) {
            missingColocatedRegions.add((ColocatedRegionDetails) detail);
        } else {
            throw new ResultDataException("Unknown type of PersistentRecoveryFailures result");
        }
    }
    boolean hasMissingDiskStores = !missingDiskStores.isEmpty();
    boolean hasMissingColocatedRegions = !missingColocatedRegions.isEmpty();
    if (hasMissingDiskStores) {
        SectionResultData missingDiskStoresSection = crd.addSection();
        missingDiskStoresSection.setHeader("Missing Disk Stores");
        TabularResultData missingDiskStoreData = missingDiskStoresSection.addTable();
        for (PersistentMemberPattern peristentMemberDetails : missingDiskStores) {
            missingDiskStoreData.accumulate("Disk Store ID", peristentMemberDetails.getUUID());
            missingDiskStoreData.accumulate("Host", peristentMemberDetails.getHost());
            missingDiskStoreData.accumulate("Directory", peristentMemberDetails.getDirectory());
        }
    } else {
        SectionResultData noMissingDiskStores = crd.addSection();
        noMissingDiskStores.setHeader("No missing disk store found");
    }
    if (hasMissingDiskStores || hasMissingColocatedRegions) {
        // For clarity, separate disk store and colocated region information
        crd.addSection().setHeader("\n");
    }
    if (hasMissingColocatedRegions) {
        SectionResultData missingRegionsSection = crd.addSection();
        missingRegionsSection.setHeader("Missing Colocated Regions");
        TabularResultData missingRegionData = missingRegionsSection.addTable();
        for (ColocatedRegionDetails colocatedRegionDetails : missingColocatedRegions) {
            missingRegionData.accumulate("Host", colocatedRegionDetails.getHost());
            missingRegionData.accumulate("Distributed Member", colocatedRegionDetails.getMember());
            missingRegionData.accumulate("Parent Region", colocatedRegionDetails.getParent());
            missingRegionData.accumulate("Missing Colocated Region", colocatedRegionDetails.getChild());
        }
    } else {
        SectionResultData noMissingColocatedRegions = crd.addSection();
        noMissingColocatedRegions.setHeader("No missing colocated region found");
    }
    return ResultBuilder.buildResult(crd);
}
Also used : PersistentMemberPattern(org.apache.geode.internal.cache.persistence.PersistentMemberPattern) CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) ColocatedRegionDetails(org.apache.geode.internal.cache.partitioned.ColocatedRegionDetails) ResultDataException(org.apache.geode.management.internal.cli.result.ResultDataException) ArrayList(java.util.ArrayList) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)

Example 5 with ResultDataException

use of org.apache.geode.management.internal.cli.result.ResultDataException in project geode by apache.

the class JsonUtil method getByteArray.

public static byte[] getByteArray(GfJsonObject jsonObject, String byName) {
    byte[] byteArray = null;
    try {
        GfJsonArray jsonArray = jsonObject.getJSONArray(byName);
        byteArray = GfJsonArray.toByteArray(jsonArray);
    } catch (GfJsonException e) {
        throw new ResultDataException(e.getMessage());
    }
    return byteArray;
}
Also used : GfJsonArray(org.apache.geode.management.internal.cli.json.GfJsonArray) ResultDataException(org.apache.geode.management.internal.cli.result.ResultDataException) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException)

Aggregations

ResultDataException (org.apache.geode.management.internal.cli.result.ResultDataException)5 GfJsonArray (org.apache.geode.management.internal.cli.json.GfJsonArray)4 GfJsonException (org.apache.geode.management.internal.cli.json.GfJsonException)4 GfJsonObject (org.apache.geode.management.internal.cli.json.GfJsonObject)2 CliJsonSerializable (org.apache.geode.management.internal.cli.result.CliJsonSerializable)2 ArrayList (java.util.ArrayList)1 ColocatedRegionDetails (org.apache.geode.internal.cache.partitioned.ColocatedRegionDetails)1 PersistentMemberPattern (org.apache.geode.internal.cache.persistence.PersistentMemberPattern)1 CompositeResultData (org.apache.geode.management.internal.cli.result.CompositeResultData)1 SectionResultData (org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)1 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)1